Tracking Branches

Tracking Branches and the Upstream Relationship

A branch's upstream is the remote-tracking branch it is compared with and pulled from by default. git branch -vv shows it with ahead/behind counts, and @{upstream} (@{u}) names it in any command:

Upstreams, ahead/behind counts and @{u}Shell
git branch -vv
git rev-parse --abbrev-ref @{upstream}
git reset -q --hard @{u}
git switch -q main
git branch -vv
Output
* dev-docs d75bb12 [origin/dev-docs: ahead 1, behind 2] Document npm run dev
  main     a2508da [origin/main] Add an npm dev script that restarts on changes
origin/dev-docs
  dev-docs 471ce3b [origin/dev-docs] List npm run dev under Run it
* main     a2508da [origin/main] Add an npm dev script that restarts on changes

"Ahead 1, behind 2" is the rejected rewrite: one local commit the remote lacks, two remote commits the branch lacks. Sam drops the rewording by resetting dev-docs to its upstream (the reflog keeps it). The counts are only as fresh as your last fetch. git branch -u sets an upstream and --unset-upstream removes it.