git checkout 远程分支失败的问题解决

##今天git checkout -b xxx origin/yyy 远程分支失败了,报错:

fatal: Cannot update paths and switch to branch ...

解决方法

git fetch -p

然后重新:

git checkout ...

-p的意思

When you fetch a remote repository, say “origin”, you will get remote branches for each branch that exists on that remote repository. Those branches are locally stored as /.

So assume origin has branches master, featureX and featureY. Then after fetching the following “remote branches” exist in your local repository: origin/master, origin/featureX and origin/featureY.

Now, imagine someone else merges featureX into master and removes the feature branch from the remote repository. Then origin only has two branches master and featureY.

However, when you fetch, the three remote branches will all still exist, including the one that was deleted in the remote repository. This is to prevent you from accidentally losing the branch (imagine someone accidentally removed the branch from the remote, then everyone who fetched from it would also lose it, making it hard to restore it).

Instead, you will need to tell the fetch command to prune any branches that no longer exist on the remote branch. So by executing git fetch –prune origin or git fetch -p the remote branch origin/featureX will be removed too.

Btw. if you want to remove a branch from a remote repository, you will have to push an “empty” branch to it, e.g. git push origin :branchname will remove the remote branch origin/branchname both locally and on the remote itself.
详见stackoverflow,the first answer.

你可能感兴趣的:(Questions)