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.

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值