如何使用Git删除远程分支?

时间:2013-07-09 10:42:22

标签: git branch git-branch

我知道之前已经介绍过,但我已经尝试了以下内容,似乎无法删除远程分支。

aly@neon:~/workspace/3DOD_VARIANCE$ git branch -a
* master
  remotes/origin/HEAD -> origin/master
  remotes/origin/master
  remotes/origin/multi_gauss_at_nodes
  remotes/origin/old-state-with-mean-deviation-from-centre
  remotes/origin/variance-branch


aly@neon:~/workspace/3DOD_VARIANCE$ git branch -r -d origin/old-state-with-mean-deviation-from-centre Deleted remote branch origin/old-state-with-mean-deviation-from-centre (was 0ed90b2).


Fetching origin
From https://bitbucket.org/alykhantejani/3dobjectdetection
 * [new branch]      old-state-with-mean-deviation-from-centre -> origin/old-state-with-mean-deviation-from-centre

正如您所看到的那样,分支已被重新获取。知道我做错了什么吗?

另外,作为旁注,有没有办法让我在删除之前检查这个分支是否已经合并回主人?

3 个答案:

答案 0 :(得分:19)

要删除远程分支运行,请执行以下操作:

git push origin :branch-to-delete

诀窍在冒号

答案 1 :(得分:17)

完整推送命令如下

git push <remote name> <local branch>:<remote branch>

只需将“no branch to all”发送到远程服务器:

git push origin :old-state-with-mean-deviation-from-centre

对于旁注:当您使用“git branch -d”时,git会阻止您删除尚未合并的分支(并告诉您如果确实要删除它,请使用-D)。

另请注意git branch -d -r <branch name>删除.git文件夹中的引用(而不是远程服务器上的真实分支),这就是为什么新的fetch会重新创建它

答案 2 :(得分:2)

git push origin :remote_branch_to_be_deleted