目前被接受的答案对我没有帮助,因为我没有要删除的远程仓库的ref - 它只存在于我的本地!所以如果你处于这种情况下,以下是需要做的:
我面临的问题如下:
$ git fetch origin
error: cannot lock ref 'refs/remotes/origin/fix/sub-branch':
'refs/remotes/origin/fix' exists; cannot create
'refs/remotes/origin/fix/sub-branch'
From <repo URL>
! [new branch] fix/sub-branch -> origin/fix/sub-branch
(unable to update local ref)
我尝试了被采纳答案的建议,但得到了这个结果:
$ git push origin :fix
error: unable to delete 'fix': remote ref does not exist
error: failed to push some refs to <repo URL>
所以引用甚至不存在于 origin
上 - 很明显它只是挂在我的本地仓库的某个地方。 因此我运行了$ git remote show me
,输出结果为:
Therefore, the reference was not even present on origin
- it was obviously just hanging around somewhere in my local repository. So, I ran $ git remote show me
, which generated:
Remote branches:
...
refs/remotes/origin/fix stale (use 'git remote prune' to remove)
...
那么问题的解决方案也就变得清晰明了:
$ git remote prune origin
Pruning origin
URL: <redacted>
* [pruned] origin/fix
有了这个,问题就消失了:
$ git fetch origin
remote: Counting objects: 5, done.
remote: Total 5 (delta 2), reused 2 (delta 2), pack-reused 3
Unpacking objects: 100% (5/5), done.
From <repo URL>
* [new branch] fix/sub-branch -> origin/fix/sub-branch