Skip to the workspace
Pebellslearn by building
Version Control with Git  ›  Lesson

Remotes — GitHub and GitLab

GitHub 14 minA remote is another copy of the repository, often hosted on GitHub or GitLab, kept in step with clone, push, fetch and pull.

frontend / Remotes — GitHub and GitLab

Explore each scene at your own pace.

01 · The rule

The rule

Remotes — GitHub and GitLab

So far the bakery's history lives only on your laptop. If the laptop dies, the history dies with it, and your friend who helps with the CSS cannot see any of it. A remote is a copy of the repository on another computer, and services like GitHub and GitLab host those copies for teams and individuals.

The rule

Your laptop and the remote are two copies; push and pull keep them in step.

Git is distributed: every clone holds the full history. A hosting service is simply one copy that everyone agrees to share. GitHub and GitLab both host Git repositories and add features around them: a web view of the code, issue tracking, code review, and automated checks. GitLab can also be installed on a company's own servers.

Connecting a remote. Create an empty repository on the service, then:

git remote add origin https://github.com/crumb-bakery/site.git
git push -u origin main
  • origin is the conventional nickname for the main remote.
  • push uploads your new commits. -u remembers that your main goes with origin's main, so later you can just type git push.

Joining an existing project. Your friend copies the whole repository, history included:

git clone https://github.com/crumb-bakery/site.git

Cloning sets up origin automatically.

Getting other people's work.

  • git fetch downloads new commits from the remote but does not touch your files or your branches. It updates origin/main, Git's local record of where the remote's main is.
  • git pull is a fetch followed by combining the remote's changes into your current branch (a merge by default, or a rebase if configured).

When a push is refused. If someone else pushed first, the remote has commits you do not. Git refuses your push rather than lose their work. Pull first, resolve any conflicts, then push again.

Hosting services also handle who may do what. A repository can be public or private, and collaborators get read or write access. Signing in from the command line usually uses an SSH key or a personal access token rather than your account password.

Scene 1 of 5
Hover to wake the cannons. Drag to move, or use arrow keys when focused. Press Enter to fire a shot.