Tag Archives: #git #git_remote #git_checkout #git_-t

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