我如何重命名尚未被推到远程仓库的本地分支 ?

相关:


当前回答

这里有三个步骤:命令, 您可以在终端内调用, 更改分支名称 。

git branch -m old_branch new_branch         # Rename branch locally
git push origin :old_branch                 # Delete the old branch
git push --set-upstream origin new_branch   # Push the new branch, set local branch to track the new remote

如果需要更多的话:一步一步,如何更改 Git 分支名称这是一篇关于这个的好文章。

其他回答

要重命名您的当前分支 :

git branch -m <newname>

更改事务组本地本地很简单...

如果您在树枝上, 您想要更改名称, 只需这样做 :

git branch -m my_new_branch

否则,如果你在master任何其他事务组而不是你想改名的,简单说说:

git branch -m my_old_branch my_new_branch

此外,我创建了下面的图像 来展示在命令行。在这种情况下,你正在master例如,分支:

Change branch name locally

如果您不想将分支推到远程服务器, 这个示例将很有用 :

假设你有一个现有的分支 叫做"我的热能特长" 你想把它改名为"特长15"

首先,你想改变你的地方分支。

git branch -m my-hot-feature feature-15

更多信息,请访问地方和远程重命名Git的一个分支.

另一个选项是根本不使用命令行。 Git GUI 客户端,例如源树树导致像这个这样的问题 成为Stack overflow最受关注的问题之一。

在 SourceTree 中,右键单击左侧“ Branches” 窗格中的任何本地分支并选择“ 重命名... ” 。

高级 Git 用户可以手动重命名 :

Rename the old branch under .git/refs/heads to the new name

Rename the old branch under .git/logs/refs/heads to the new name

Update the .git/HEAD to point to yout new branch name