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:

  • 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)

Documentation / Reference





Discover More
Git - Fetch (Remote Repository Sync)

A fetch will sync information locally from a remote repository. It will mostly git fetch: download new remote branch download all commits added since the last fetch to the actual branch ( The head...
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 - Push

push will send branch to the remote creating remote branch Git automatically expands the branchName out to refs/heads/branchName:refs/heads/branchName, which means: Take my branchName local branch...
Git - Remote (Tracked Repository)

A remote in Git is a remote repository (ie a remote git server). Git remote manage the set of repositories (“remotes”) whose branches you track. They are also called tracked repositories in reference...
Git - Upstream Branch (Tracking branch)

An upstream is a configuration of a local branch that set the remote branch that it's tracking. cloning @{u} or @{upstream} means the upstream branch of the current branch @{upstream} or @{u}...
What is a Git Checkout?

With a checkout, you can change the current branch (ie switch branches) or extract files/directory from branches into the working tree (file system directory) files. ie: Restore the file state from...



Share this page:
Follow us:
Task Runner