2012-01-07 87 views
109

這可能是一個愚蠢的問題,但我是全新的git,並且看到一個不再存在的遠程分支。'git branch -av'顯示不再存在的遠程分支

$ git branch -a 
* master 
    remotes/origin/master 
    remotes/origin/production 

我不認爲生產分支是遠程存在的,不知道它爲什麼仍然顯示在本地。我如何刪除/刪除這個分支?下面是試圖刪除它看起來像:

$ git push origin :production 

error: unable to push to unqualified destination: production 
The destination refspec neither matches an existing ref on the remote nor 
begins with refs/, and we are unable to guess a prefix based on the source ref. 
error: failed to push some refs to '[email protected]:puppet.git' 

我可以簽出所謂遠程分公司生產,但得到這樣的:

$ git checkout origin/production 
Note: checking out 'origin/production'. 

You are in 'detached HEAD' state. You can look around, make experimental 
changes and commit them, and you can discard any commits you make in this 
state without impacting any branches by performing another checkout. 

If you want to create a new branch to retain commits you create, you may 
do so (now or later) by using -b with the checkout command again. Example: 

    git checkout -b new_branch_name 

HEAD is now at c323996... added powerdns module, no really 

我不知道到底我在做什麼。任何幫助,將不勝感激。

+0

'git fetch'後git branch -a的輸出是什麼? – alediaferia 2012-01-07 01:20:27

+2

仍然相同。 – CarpeNoctem 2012-01-07 01:47:33

+0

可能重複[如何強制刪除GitHub中的遠程分支?](http://stackoverflow.com/questions/8754183/how-to-forcefully-delete-remote-branch-in-github) – Cascabel 2012-01-07 02:03:31

回答

210

你要做的:

git remote prune origin 
+4

謝謝你的工作!你能詳細說明幕後發生了什麼嗎? – CarpeNoctem 2012-01-07 01:46:47

+7

這些是您本地倉庫的遠程追蹤分支,如果分支在遠程倉庫中被刪除,您必須清除它們。 – manojlds 2012-01-07 01:47:46

+0

你做了我的一天。 – 2017-02-06 21:32:00

40

因此,有兩個問題。在這兩種情況下,請記住Git是分發的。

第一。當你不喜歡的東西-a

在您的本地回購不是遠程計算機執行的操作

$ git的分支。換句話說,你的本地回購是報告所有知道的分支。這些可能是本地分支(如'主')或遠程分支,它從遠程獲取。自上次獲取以來,遠程倉庫的「生產」分支已發生變化,但您的本地倉庫並不知道這一點。 manojlds的答案是正確的。運行

$ git的遠程修剪起源

刪除陳舊的分支機構。

'git push origin:production'命令用於從遠程計算機的git repo中刪除分支。不是你當地的回購。在這種情況下,其他人已經刪除了遠程計算機的git repo上的分支,因此您會看到此錯誤消息。

這裏是總結這些命令的link

第二個問題涉及結帳。

檢出分支時,您希望從本地分支,而不是遠程分支。這就是爲什麼你會得到關於分離HEAD的錯誤。這個git-notes repo對這個問題有很好的解釋。基本上,關鍵短語是

但是,當您簽出不合適的本地分支名稱時,HEAD不再是對任何事物的符號引用。相反,它實際上包含您要切換到的提交的SHA-1哈希(提交ID)。

現在,如何簽出一個本地分支,就像遠程分支一樣?

很簡單,你創建一個本地分支,在結賬時遠程分支。

$ git的結帳-b my_local_branch產地/生產

10
git remote prune origin 

是正確的,只是增加你可以使用--dry-run選項,報告的是分支將從本地回購被修剪,但實際上犯規修剪它們

git remote prune origin --dry-run