2013-07-19 62 views
15

我想刪除我的項目存儲庫的一些遠程分支。我已經運行的下一個命令:刪除Git中的遠程分支

git push origin :name_of_branch 

,當我列出遠程分支機構與

git branch -r 

,我已經刪除,不能出現分支,但我的一個夥伴運行

git fetch 

後來

git branch -r 

和在列表中,我已刪除的分支name_of_branch仍在列表中。然而,當他試圖刪除與

git push origin :name_of_branch 

他收到一條消息分支:

error: unable to delete 'name_of_branch': remote ref does not exist 
error: failed to push some refs to 'the_name_of_the_repository' 

我怎麼會完全刪除列表中的分支?

+0

Duplicate [刪除本地和遠程Git分支?](http://stackoverflow.com/q/2003505/456814)。 – 2014-06-06 03:22:01

回答

23

這是因爲當你的這種合作伙伴運行git fetch,分支刪除不「適用」到他的倉庫。 fetch只更新並添加分支。

他們可以運行git remote prune origin修剪掉上游存儲庫中不再存在的列表中不再存在的遠程分支。

+4

僅供參考,'git remote prune'有點不贊成'git fetch --prune'或'git fetch -p'。請參閱[Git版本1.6.6發行說明](https://github.com/git/git/blob/v2.0.0/Documentation/RelNotes/1.6.6。txt#L162-L166):「['git fetch --prune'make]'git remote update'和'git remote prune' less less necessary(沒有計劃移除'remote update'或'remote prune',雖然)「。 – 2014-06-06 03:19:13

1
git branch -r -d 'remote-branch' 
9

git fetch --prune <remote>可用於刪除跟蹤遠程存儲庫中不再存在的分支的所有遠程跟蹤分支(即它們已在遠程存儲中被刪除)。從official Linux Kernel Git documentation for fetch

-p

--prune

取後,除去任何遠程跟蹤分支,其遙控器上不再存在。

您可以用命令

git branch -D -r <remote>/<branch> 

the documentation for git branch規定也遠程遙控陳舊跟蹤分支機構:

使用-r-d一起刪除遠程跟蹤分支。請注意,如果遠程跟蹤分支不再存在於遠程存儲庫中,或者git fetch已配置爲不再獲取它們,則只有刪除遠程跟蹤分支纔有意義。