Git - Tracking Branch

1 - About

Tracking branches are local branches that have a direct relationship to a remote branch.

If you’re on a tracking branch and type git pull, Git automatically knows which server to fetch from and which branch to merge in.

3 - Management

3.1 - Create

Checking out a local branch from a remote-tracking branch automatically creates a tracking branch (and the branch it tracks is called an upstream branch).

If the branch name you’re trying to checkout doesn’t exist and exactly matches a name on only one remote, Git will create a tracking branch for you

git checkout remote/branchName
Branch branchNameset up to track remote branch branchName from remote.
Switched to a new branch 'branchName'

Other syntax:

git checkout --track remote/branchName
git checkout -b <branch> <remote>/<branch>

3.2 - List

git fetch --all
git branch -vv
  iss53     7e424c3 [origin/iss53: ahead 2] forgot the brackets
  master    1ae2a45 [origin/master] deploying index fix
* serverfix f8674d9 [teamone/server-fix-good: ahead 3, behind 1] this should do it
  testing   5ea463a trying something new


  • branch iss53 is tracking origin/iss53 and is
    • ahead by two commit (two commits were not pushed to the server)
  • the branch server-fix-good branch on the teamone server is:
    • ahead by three (three commits locally that we haven’t pushed)
    • behind by one (one commit on the server has not been merged)

4 - Documentation / Reference

code/version/git/tracking.txt · Last modified: 2018/06/11 15:12 by gerardnico