Git checkout to a remote branch

There are many ways to checkout to a remote branch of a repository. The simplest one is creating a new branch in your local repository with the same name of the remote one, git fetch, and then git checkout to the new branch.

But there is an even simpler way to do so, with the use of a single git flag: -t <remote_branch>

Like this:

14:01:38 ✘ dbkreling:(master)~/my-application/src$ git branch -r
 origin/HEAD -> origin/master
 origin/develop
 origin/master
 origin/release

I want to checkout the develop branch, still not one of my branches. Then:

14:03:44 ✔ dbkreling:(master)~/my-application/src$ git checkout -t origin/develop
 Branch develop set up to track remote branch develop from origin.
 Switched to a new branch 'develop'

 14:06:36 ✔ dbkreling:(develop)~/my-application/src$ git branch
 * develop
 master

Hope it helps.

Cheers!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s