2016-07-11 38 views
2

我對這個GitHub的倉庫中的單一分支(未掌握),現在我想重新命名它,由於某種原因,我得到這個錯誤:的Git拒絕刪除分支

git push origin :OldName 
To [email protected]:user/gitRepo.git 
! [remote rejected] OldName (refusing to delete the current branch: refs/heads/OldName) 
error: failed to push some refs to '[email protected]:user/gitRepo.git' 

這是因爲我沒有任何主分支?這裏是我的git branch -a

OldName 
remotes/origin/HEAD -> origin/OldName 
remotes/origin/OldName 

回答

4

如果從git branch -a輸出是準確的,那麼看來你只有一個分支OldName,單相應的分支通過GitHub上的同名。刪除存儲庫中唯一的分支沒有多大意義,因爲那樣在該存儲庫中不會有任何內容(不包括reflog,如果仍然存在的話)。

具體而言,錯誤可能是由於稍有不同的原因造成的。由於OldName分支是GitHub中唯一的分支,因此也很可能是默認分支用於存儲庫。 GitHub不允許你刪除默認分支,因爲這意味着瀏覽你的回購站的用戶可能無法看到內容。

要解決這個問題,你可以從那裏創造你想要的名稱的分支,並執行刪除操作:

本地

git checkout -b NewName # create a dummy branch from OldName 
git push origin NewName 

在GitHub上

將默認分支更改爲NewName

本地(再次):

git push origin :OldName