Table of Contents

Git - Tracking Branch

About

Tracking branches are local branches that have set their upstream branch.

Technically, when a local branch got an upstream, a tracking branch is created as a local reference to a remote branch and is not a local branch.

The local branches have then a direct relationship with their upstream branch that can be:

When you pull, Git automatically knows:

Management

Create

Check out a remote branch

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>

Setting the upstream branch

git checkout --track remote/branchName

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

where:

Documentation / Reference