Git - Upstream Branch (Tracking branch)


An upstream is a configuration of a local branch that set the remote branch that it's tracking.

By default, when cloning, each local branch gets as upstream the remote branch of the cloned remote repository.

Name Shorthand

@{u} or @{upstream} means the upstream branch of the current branch

  • @{upstream}
  • or @{u}

Usage example with the merge command

git merge @{u}



git branch -vv
* main 876e695 [origin/master: gone] Error in travis.yml

Set / Update

You update/set an upstream with the branch command

git branch -u origin/branchName
# or
git branch --set-upstream-to origin/branchName
Branch branchName set up to track remote branch branchName from origin.

You can also set it with a push

git push -u origin master
git push --set-upstream origin master


Add the upstream of your fork as remote

git remote add upstream


git remote -v
origin (fetch)
origin (push)
upstream (fetch)
upstream (push)

You got the origin and the upstream (the forked repo)

Fetch (Sync)

git fetch upstream 

Output example

remote: Enumerating objects: 56, done.
remote: Counting objects: 100% (56/56), done.
remote: Compressing objects: 100% (3/3), done.
Receiving objects:  73% (134/183)sed 54 (delta 53), pack-reused 127 eceiving objects:  67% (123/183)
Receiving objects: 100% (183/183), 40.48 KiB | 1010.00 KiB/s, done.
Resolving deltas: 100% (103/103), completed with 23 local objects.
 * [new branch]      master     -> upstream/master
 * [new tag]         2018-04-30 -> 2018-04-30


# Go to the main branch (default)
git checkout main
# merge the upstream main branch in the checked out branch
git merge upstream/main
git merge upstream/master
# Shorthand
git merge @{u}


Local Branch vs upstream

  • Description
git log [email protected]{u} --oneline
71bfc15 (origin/master) Added ansible-config cli
c4c7124 Added ansible-inventory
  • Count
git rev-list [email protected]{u} --count

Upstream vs local branch

git log @{u}..HEAD --oneline
afc0e4b (HEAD -> master) private key enhancement


fatal: no upstream configured for branch 'master'

Example on the master branch

git branch --set-upstream-to origin/master

Powered by ComboStrap