$ git fetch
$ git checkout <branch>
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 <branch>
. 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.
To fetch a branch, you simply need to: