Remotes, Fetch, Pull, Push and Tags
Remotes are named URLs, and remote-tracking branches like origin/main are your local cache of where the remote's branches were at your last fetch. Fetch downloads, pull integrates, push uploads, and tags travel only when you ask.
Key points
- 1
git fetchupdatesorigin/*refs only; your branches, index and files never change.git pullis fetch plus merge (or rebase). - 2
Remote-tracking refs change only on fetch, pull or push, so
git statusahead/behind counts are as stale as your last fetch. - 3
A push must be a fast-forward of the remote branch; "rejected (fetch first)" means someone pushed first, so fetch and integrate before pushing again.
- 4
With
push.default = simple, a branch without an upstream needsgit push -u origin <branch>, or setpush.autoSetupRemote = true. - 5
Tags are not pushed by default: use
git push origin <tag>,--follow-tags(annotated, reachable) or--tags(all).git describeuses annotated tags unless you pass--tags. - 6
Deleted remote branches linger locally until
git fetch --prune; tags need--prune-tags. - 7
--depthimplies--single-branch; partial clones (--filter=blob:none) keep full history and fetch file contents on demand.
Common traps
A plain
git fetchnever moves a tag you already have; moving a published tag silently leaves teammates on the old commit.On Windows, Git for Windows' system config sets
pull.rebase = false, sogit pullmerges where a clean Linux Git would stop and ask.Fork pull requests don't get repository secrets in
pull_requestworkflows, andGITHUB_TOKENis read-only.
Further reading
Suggest a resource- Dealing with diverged git branches(opens in a new tab)Julia Evans on the choices when local and remote branches have both moved: merge, rebase or force-push.Articlejvns.caEditor’s pick
- Pro Git: The refspec(opens in a new tab)How fetch and push map remote refs to local ones.Docsgit-scm.comEditor’s pick
- git-push documentation(opens in a new tab)Push options including --force-with-lease and upstream tracking.Docsgit-scm.comEditor’s pick
Test yourself on Remotes, Fetch, Pull, Push and Tags
Ten questions, with the answer and explanation after each one.