本地删除无效的远程分支

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值