2012-10-20 51 views
1

我使用GIT來管理項目的源代碼,使用本地SourceTree和BitBucket遠程託管代碼。我做了一個叫「MyFeature」的新分支。在某些時候,我重新命名了分支,比如說「features/MyFeature」,這樣分支會更好地組織起來(我現在有比以前更多的分支)。但是,現在似乎在BitBucket上有兩個分支 - 「MyFeature」和「features/MyFeature」。有沒有辦法從BitBucket中刪除舊分支,以便只有一個分支「features/MyFeature」?重命名分支的最佳方式是什麼,以便分支名稱在GIT存儲庫的不同簽出中保持一致?重命名本地GIT分支不會更改'Origin'上的名稱

回答

4

從遠程,使用混帳推刪除了一個分支:其他克隆的

git push origin :branch-to-delete 

用戶必須重訂其地方分支機構到改名分支。不幸的是,沒有辦法讓分行名稱自動同步。

+0

謝謝!完美工作。只要注意「:」實際上是必要的。 – Jason

+1

是的,冒號很重要。推入refspecs總是'local:remote' - 如果省略local,則刪除remote。 – knittl

0

要重命名的本地和遠程分支我用下面的命令:

git checkout <old_branch_name> # to switch on branch 
git branch -m <new_branch_name> # to rename local branch 
git push origin :<old_branch_name> # to delete old remote branch 
git branch --unset-upstream # to remove tracking from old remote branch 
git push --set-upstream origin <new_branch_name> # to push and create new remote branch