hi all:
如何让已经失效的远程 branch-name 在执行 git branch -a
的时候不再展示?
有同事push 了一个git分支,并且被我给pull 到本地了
同事在自己机器上执行了
git branch -d branch-name
git push origin :branch-name
我在自己机器执行
git branch -d branch-name
//ok
git push origin :branch-name
//提示:
error: unable to delete 'branch-name': remote ref does not exist
error: 无法推送一些引用到 'git@gitserver:phplib'
大家帮忙想想办法让已经失效的远程 branch-name 在执行 git branch -a
的时候不再展示吧?谢谢
reply:
git remote prune origin
清理远程分支,把本地不存在的远程分支删除
删除了远程的master分支后,客户机再pull代码可能会有问题,提示默认的分支指向了不存在的ref。可参考下面的办法解决:
删除一个远程分支时出现错误提示:
1
|
$ git push --delete origin foobar
|
remote: error: By default, deleting the current branch is denied, because the next
remote: error: 'git clone' won't result in any file checked out, causing confusion.
remote: error:
remote: error: You can set 'receive.denyDeleteCurrent' configuration variable to
remote: error: 'warn' or 'ignore' in the remote repository to allow deleting the
remote: error: current branch, with or without a warning message.
remote: error:
remote: error: To squelch this message, you can set it to 'refuse'.
remote: error: refusing to delete the current branch: refs/heads/foobar
To cisvr:~/reis.git
! [remote rejected] foobar (deletion of the current branch prohibited)
error: failed to push some refs to 'cisvr:~/reis.git'
也就是foobar是远程仓库的当前分支(由于使用git clone --bare
生成裸仓库造成的),因为远程仓库是裸仓库,所以不能使用普通的git checkout命令切换分支。在裸仓库中使用如下命令来切换当前分支:
1
|
$ git symbolic-ref HEAD refs
/heads/devel
|
这样就将裸仓库的当前分支切换为devel分支,删除foobar分支就没问题了。
1
|
$ git push origin :foobar
|
这个命令实质上是修改了.git/HEAD文件,使其内容为:
1
|
ref: refs
/heads/devel
|