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.
Test yourself on Remotes, Fetch, Pull, Push and Tags
Ten questions, with the answer and explanation after each one.