How to checkout a remote branch in Git?

Misha Moroshko picture Misha Moroshko · Jan 16, 2012 · Viewed 77.3k times · Source

Someone pushed a "new feature" branch to the shared repo:

git push -u new_feature_branch

Now, I would like to create a copy of this branch on my local machine in order to test the new feature.

What would be the easiest way to do this? (Do I need to fetch / pull before checkout?)

Answer

Bill Door picture Bill Door · Jan 16, 2012

I generally find it unnecessary to use git fetch. git pull is sufficient. git pull will synchronize your repository with the remote. The new_feature_branch will then be available.

git checkout new_feature_branch will notice the branch in origin and create a new local tracking branch for you and switch to that branch.

git pull
git checkout new_feature_branch