Remotes and GitHub — Push, Fetch, Pull
Your repository lives on your laptop. The deploy server, your teammates and the CI system all need the same history. A hosted remote, most often on GitHub, is the shared meeting point everyone syncs with.
The rule
Your repo is complete locally; push and pull only sync it with a remote.
Every Git clone holds the full history. A remote is simply another copy of the repository at a URL, conventionally named origin. GitHub hosts such copies and adds a web interface, access control, issues, pull requests and automation around them.
git clone git@github.com:acme/notes-api.git # copy the repo and set origin
git remote -v # list remotes and their URLs
git push -u origin feature/search # publish a branch, remember the link
git fetch origin # download new commits, change nothing locally
git pull # fetch, then merge into your branch- push sends your commits to the remote branch.
- fetch downloads the remote's new commits into tracking branches such as
origin/main, without touching your work. - pull is fetch plus merge (or rebase, if you configure it).
For authentication GitHub accepts SSH keys (URLs like git@github.com:...) or HTTPS with a personal access token. Account passwords do not work for Git operations.
If the remote has commits you do not have, Git rejects your push as "non-fast-forward". It will not overwrite others' work. You pull, resolve any conflicts, and push again.
The shortcut
Think of origin/main as a photo of the remote, taken at your last fetch. Before you push, refresh the photo (git fetch), compare, then act. git status then tells you whether you are ahead, behind or both.
Push fails
git pushonmainis rejected: the remote contains work you do not have.
The trap is git push --force to make the error go away. It replaces the remote branch with yours and deletes teammates' commits there.
Drills
Answer fast — trust the rule.
What does git fetch change in your working files?
What is git pull equivalent to by default?
Your push is rejected as non-fast-forward. What is the safe fix?
What is origin, by convention?
Remember
- Your repo is complete locally; push and pull only sync it with a remote.
- Shortcut:
origin/mainis a photo from your last fetch. Refresh, compare, then act. - Trap:
git push --forceon a shared branch.
