Skip to content

Instantly share code, notes, and snippets.

@inoas
Forked from markSci5/Git checkout remote branch
Created November 10, 2016 14:45
Show Gist options
  • Save inoas/9dfd4257f993535c19c8da78c97c4537 to your computer and use it in GitHub Desktop.
Save inoas/9dfd4257f993535c19c8da78c97c4537 to your computer and use it in GitHub Desktop.
Git checkout remote branch
//To fetch a branch, you simply need to:
git fetch origin
//This will fetch all of the remote branches for you. With the remote branches
//in hand, you now need to check out the branch you are interested in, giving
//you a local working copy:
git checkout -b test origin/test
//Or
git branch test origin/test
@inoas
Copy link
Author

inoas commented Nov 10, 2016

With newer versions of git you can just enter:

$ git fetch
$ git checkout

git fetch will fetch all the remote branches, which you can verify with git branch -r (or git branch -rv), and as long as you don't have an existing branch with the name you want, you can just switch directly to it with git checkout . All this behavior assumes the default configuration for fetching "refs" for all remote branches and tags, which you can override with options or by configuring the remote. See git fetch --help for details. I like to also include the -p (--prune) option for removing dead remote-tracking refs for refs that have since been deleted on the remote.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment