Shihui Guo

Pull a new branch from remote repo

The wrong way to do is:

git checkout -b new_branch
git pull origin new_branch

But please do it in this way:

git checkout -b new_branch origin/new_branch

Though seemingly the same, these two ways are significantly different:
The first one checkout the new branch from existing branch (maybe master), and merge it with the remote new_branch, this is not really what we want
The second does the clean job, just set up to track the remote new_branch and got nothing to do existing local branch.

But if you meet the following error:

fatal: git checkout: updating paths is incompatible with switching branches.

This error occurs mostly because you want to check out a branch which your local git repo is not aware of, which means the remote branch is totally new. So update the local git repo before checking out the new branch:

git remote update
git checkout -b new_branch origin/new_branch
点击查看评论