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}



With Git - rev-parse

git rev-parse --abbrev-ref branch@{u}

Example for the current local branch:

echo $(git rev-parse --abbrev-ref "@{u}")

Tip: you can also build it from the config info:

remote="$(git config "branch.${branch}.remote")"
remote_branch="$(git config "branch.${branch}.merge" | cut -d/ -f3-)"
echo "$remote/$remote_branch";


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 remoteName

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 HEAD..@{u} --oneline
71bfc15 (origin/master) Added ansible-config cli
c4c7124 Added ansible-inventory

  • Count
git rev-list HEAD...@{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

Discover More
Git Commit Tree Data Model
Git - Commit

A commit in git is an object that stores the information : who saved the file system snapshots, when they were saved, why they were saved. the commiter the author the parent commit It's...
Git - Current / working / HEAD / active branch

The current or active branch is: the branch checked out actually in the working tree The current branch is also known as the HEAD branch (in uppercase) that represents the last commit known...
Git - Fork (Upstream)

A fork is an entire copy of a repository. The original repository of a fork is known as the upstream repository. It has the same concept as a upstream branch. see To sync your local repo with...
Commit History Forked
Git - Forked commit management

This is a page a local fork (ie a local branch). remote fork To incorporate the new commits into your feature branch, you have two options: merging or rebasing. Forked commit history
Git - Head (Head Branch | Branch Head)

The head is the last commit of a branch. while the HEAD (in uppercase) is the head of the current branch (active branch). headHEADcurrent branch page In the example below, the branch head of: ...
Git - Local branch

A local branch is a branch that exists only on your computer. tracking branch There are two types of local branches: non-tracking local branches. They are not associated with any other branch....
Git - Pull

git pull incorporates commit (changes) from: a remote repository into the current branch. In its default mode, git pull is a shorthand for: git fetch followed by git merge ie git merge FETCH_HEAD...
Git - Remote branch

A remote branch is a branch in a remote repository. (remote reference). Example: where: and To get the commit from a remote branch, you do a pull (ie a git fetch followed by git...
Git - Tracking Branch

Tracking branches are local branches that have set their upstream branch. tracking branchreference The local branches have then a direct relationship with their upstream branch that can be: a remote...
Branches Git
Git - Branch

This page talks Branch management in Git. For Git, a branch is: a commit name (ref) that points to the last commit (head) leaf in the commit log (or log) that represents a commit chain Example...

Share this page:
Follow us:
Task Runner