Module 5: Remote Collaboration and Protected Branches
Remote Tracking Refs, Upstream Branches, and Fetch Specs
Remote Tracking Refs, Upstream Branches, and Fetch Specs
Module: Module 5: Remote Collaboration and Protected Branches
Remote collaboration is built on refs. origin/main is not the remote branch itself; it is your local remote-tracking ref updated by fetch. Upstream configuration tells Git which remote branch a local branch follows.
Understanding this distinction prevents confusion after a teammate pushes. Your local origin/main is stale until you fetch. Your local main is separate again. Pull combines fetch plus integration, while fetch alone gives you the chance to inspect before changing your branch.
Fetch specs define which remote refs are copied into which local tracking refs. Most users never edit them, but knowing they exist helps when working with forks, mirrored repositories, or unusual branch namespaces.
Command Walkthrough
git remote -v
git branch -vv
git fetch origin
git branch --set-upstream-to=origin/main main
git for-each-ref refs/remotes --format='%(refname:short) %(objectname:short)'
git config --get-all remote.origin.fetchorigin/main d4e5f6a
origin/feature a1b2c3dHands-on Lab
Clone a temporary copy of your practice repository into another directory. Push a branch from one clone, fetch it in the other, and inspect branch -vv plus refs/remotes before and after fetch.
What to Watch For
- origin/main can be stale. Fetch before making decisions about remote state.
- Deleting a local branch does not delete the remote branch unless you push a deletion.
- Tracking configuration affects default pull and push behavior. Verify it when commands surprise you.
Completion Check
You should be able to explain what each command changed, inspect the resulting history, and describe how you would undo or recover from the operation before using it in a shared repository.