Git Reference ยท Revisions and Pathspecs
Upstream names: @{upstream} and @{push}
Reference for Git @{upstream}, @{u} and @{push}: refer to a branch's tracking branch, compare ahead and behind counts and handle triangular workflows.
A local branch can track a branch on a remote: main tracks origin/main. Two revision suffixes name that other end without spelling it out. @{upstream} (short form @{u}) is the branch you normally pull from. @{push} is the branch you normally push to. For most projects they are the same, but in a fork workflow they differ.
Because the suffixes follow your configuration, the same command works on every branch: git log @{u}.. shows what you have not pushed, and git log ..@{u} shows what is waiting to be merged.
git log @{u}.. # commits you have that upstream lacks
git diff @{u} # compare working tree with upstream
git rev-list --left-right --count @{u}...HEAD # behind <TAB> ahead
Try it
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.
Syntax
<branch>@{upstream} # also @{u}; omit <branch> for the current branch <branch>@{push}
| Form | Meaning |
|---|---|
@{upstream}, @{u} |
The remote-tracking branch the current branch is configured to track (branch.<name>.remote and branch.<name>.merge). |
main@{upstream} |
The same for branch main, whichever branch is checked out. |
@{push} |
The remote-tracking branch that git push would update for the current branch. |
main@{push} |
The same for branch main. |
@{push} is worked out from branch.<name>.pushRemote, remote.pushDefault, push.default and the remote's push refspec. With the default settings it equals @{upstream}.
Errors:
fatal: no upstream configured for branch 'x'when the branch tracks nothing.fatal: upstream branch 'refs/heads/y' not stored as a remote-tracking branchwhen the remote's fetch refspec does not map that branch.
Usage notes
- Set the upstream with
git push -u origin mainorgit branch --set-upstream-to=origin/main.git cloneandgit switch <name>(which creates a tracking branch from a unique remote branch) set it for you. - They are remote-tracking names.
@{u}is the local copy of the remote branch, updated bygit fetch. It does not contact the server, so fetch first when you want fresh answers. - Read the counts.
git rev-list --left-right --count @{u}...HEADprints two numbers: commits only upstream (behind), then commits only local (ahead).git status -sbandgit branch -vvshow the same information. - Triangular workflows. When you fetch from the project (
@{u}) and push to your fork (@{push}),git log @{push}..shows what has not reached your fork andgit log @{u}..what is not yet in the project. - Use in rebase and merge.
git rebase @{u}andgit merge @{u}are whatgit pull --rebaseandgit pulldo after fetching. - Quote in shells that treat braces specially:
'@{u}'.