The most easiest way to download a new branch from remote repository is :
# Download a new remote branch named topic and switch to topic $ git checkout topic
What above command do includes :
- Fetch topic branch from remote
Set up its upstream branch :
Here topic is tracking
<remote>/topic. Thus when you execute
git pull, Git will know where to get update.
Switch to topic branch
$ git checkout --track origin/topicdoes the same thing with
$ git checkout topic.
--tracksets up which remote branch the new branch is tracking.
-bis ignored, meaning the new branch is derived from the remote branch.
git chekcout <remote-branch-name> a shortcut, if you want to give a different branch name with the remote one, use the full format :
# Create a new branch from a remote branch and switch to it. $ git checkout -b <branch> <remote>/<branch> # Examples: # Create a new branch setupfix from origin/issue13 and switch to setupfix. $ git checkout -b setupfix origin/issue13