What is a remote-tracking branch, and what is an upstream branch?

Git & SDLC Remotes Intermediate 1–2 Yrs2–3 Yrs Conceptual 1 min read

Quick Answer

A remote-tracking branch (origin/main) is a local, read-only pointer to where a branch was on the remote at your last fetch. An upstream is the remote branch your local branch is configured to compare/push/pull against — set with git push -u origin feature or git branch --set-upstream-to.

A remote-tracking branch like origin/main is my local snapshot of where main was on the server the last time I fetched — I can't commit to it, it just moves when I fetch. The upstream is the link between my local branch and a remote branch, so that git status can tell me I'm two commits ahead and one behind, and so that a bare git push or git pull knows the target. I set it the first time with git push -u.

  • git status shows “ahead 2, behind 1” by comparing your branch to its upstream.
  • git fetch updates origin/*; your local branches don't move until you merge/rebase/pull.
  • With an upstream set, plain git push and git pull know where to go.