Git & GitHub Interview Question #36
What is an upstream branch in Git?
Remotes, Fetch, Pull, Push, Merge, Conflicts, Rebase & Stash Junior Beginner
Quick Interview Answer
An upstream branch is the branch that a local branch is configured to track, commonly a remote-tracking branch such as origin/main or origin/feature/search.
Detailed Explanation
An upstream branch is the branch that a local branch is configured to track, commonly a remote-tracking branch such as origin/main or origin/feature/search.
Once tracking is configured, commands such as git pull and git push can often infer the intended branch. git status can also report whether the local branch is ahead of or behind its upstream.
Code Example
git push -u origin feature/search
# Inspect tracking information
git branch -vv