Tracking Upstream Branches
Upstream tracking is a relationship between a local branch and a remote branch. Once set, git push, git pull, and git status all automatically know which remote branch to use — no need to type "origin main" every time.
01.What Tracking Does For You
When a local branch tracks a remote branch, git status shows "Your branch is 2 commits ahead of origin/main". git push knows where to send your commits. git pull knows where to pull from. No more typing "origin main" every single time. This tracking relationship is stored in .git/config per branch.
02.Viewing and Setting Tracking
git branch -vv shows all local branches with their tracking relationship and ahead/behind counts. If a branch has no tracking, set it with git branch --set-upstream-to or by using the -u flag on your next push. Cloning sets this up automatically for the default branch.
Commands
What is the main benefit of setting an upstream tracking branch?