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
originfor 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.
Start fresh
git switch mainthengit pull. Yourmainnow matches the shared one.
Drills
Answer fast — trust the rule.
Which statement about Git and GitHub is true?
What does git clone give you?
What is the difference between git fetch and git pull?
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.
