If you have just one remote, the easiest way to check out a new branch from the remote is:
# Download a new remote branch named topic and switch to that branch $ git checkout topic
What above command does includes :
- Fetch “topic” branch from remote
- Set up its upstream branch :
Here the branch “topic” is tracking
/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 topicif you just have one remote like it is named origin.
--tracksets up which remote branch the new branch is tracking.
-bis ignored, meaning the new branch is derived from the remote branch.
git chekcout a shortcut. If you have multiple remotes or you want to give a different branch name with the remote one, use the full format which specifies the remote:
# 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