Pebellslearn by building
0%
RoadmapsMatrixCoursesSandboxSign in
Version Control with Git  ›  Lesson

Remotes — GitHub and GitLab

GitHub 12 minGitHub and GitLab host copies of a Git repository called remotes, and you clone, push and pull to keep your local copy and the shared copy in step.

Remotes — GitHub and GitLab

Your commits live on your laptop. If the laptop dies, so does the history, and your teammates cannot see any of it. A shared copy of the repository on a hosting service fixes both problems, and it is where most teams do their daily work.

The rule

Git keeps history; a remote shares it. Push to give, pull to get.

Git is the version-control tool that runs on your computer. GitHub and GitLab are services that host Git repositories online and add team features on top: access control, issues, code review and automated pipelines (CI). Bitbucket and self-hosted GitLab work the same way. Git works perfectly without any of them; they are simply the most common meeting point.

A remote is a named link to another copy of the repository. The default name is origin.

git clone https://github.com/bookshop/api.git   # copy repo + full history
git remote -v                                   # list remotes
git push origin main                            # send my new commits
git fetch                                       # download others' commits, change nothing locally
git pull                                        # fetch, then merge into my branch
  • clone copies the entire history, not just the latest files, and sets up origin for you.
  • push uploads commits you have and the remote lacks.
  • fetch downloads commits you lack, without touching your files.
  • pull is a fetch followed by a merge (or a rebase, if configured).

If a teammate pushed to main after your last pull, your push is rejected: the remote has commits you do not have, and accepting yours would throw theirs away. You pull first, resolve any conflicts, then push again.

To push, and to read private repositories, you prove who you are with an SSH key or an access token. GitHub, for example, no longer accepts your account password for Git over HTTPS.

The shortcut

Think of two copies with a gap between them. Push closes the gap from you to them; pull closes it from them to you. Before starting work, pull. Before pushing, expect that someone else may have pushed first.

A normal day on the bookshop teamStep 1 of 4
  1. Start fresh

    git switch main then git pull. Your main now matches the shared one.

Drills

Answer fast — trust the rule.

quick drill

Which statement about Git and GitHub is true?

quick drill

What does git clone give you?

quick drill

What is the difference between git fetch and git pull?

quick drill

Your push to main is rejected because the remote has commits you lack. What is the safe next step?

Remember

  • Git keeps history; a remote shares it. Push to give, pull to get.
  • Clone copies everything; fetch downloads; pull downloads and merges.
  • A rejected push means pull first. Never force-push over other people's work.

Practice — level up

0/1 solved

Write your answer, then compare it with a rubric and a model answer.

ExplainSharing your work

Explain the difference between Git and GitHub, and describe what git clone, git push and git pull each do when you join the bookshop team. What happens if you try to push after a teammate has pushed first?