1

我使用 GIT 管理项目的源代码,使用本地 SourceTree 和 BitBucket 远程托管代码。我创建了一个新分支,名为“MyFeature”。在某个时候,我将分支重命名为“features/MyFeature”,以便更好地组织分支(我现在拥有比以前更多的分支)。但是,现在在 BitBucket 上似乎有两个分支——“MyFeature”和“features/MyFeature”。有没有办法从 BitBucket 中删除旧分支,以便只有一个分支“features/MyFeature”?重命名分支以使分支名称在 GIT 存储库的不同签出中保持一致的最佳方法是什么?

4

2 回答 2

4

要从远程删除分支,请使用 git push:

git push origin :branch-to-delete

其他克隆的用户必须将他们的本地分支重新定位到重命名的分支上。不幸的是,没有办法让分支名称自动保持同步。

于 2012-10-20T15:46:38.667 回答
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
于 2016-03-25T10:23:13.870 回答