Track a new remote branch created on GitHub

MLister picture MLister · Jun 29, 2012 · Viewed 138.9k times · Source

I have already got a local master branch tracking the remote master branch of a github project. Now, a collaborator of mine has created a new branch in the same project, and I want to do the following accordingly:

  1. create a new branch locally
  2. make this new branch track the newly create remote branch.

How should I do it properly?

Answer

max picture max · Jun 29, 2012
git fetch
git branch --track branch-name origin/branch-name

First command makes sure you have remote branch in local repository. Second command creates local branch which tracks remote branch. It assumes that your remote name is origin and branch name is branch-name.

--track option is enabled by default for remote branches and you can omit it.