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

相关:


当前回答

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

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

其他回答

到目前为止,答案是正确的,但以下是一些补充信息:

人们可以安全地将分支名称重新命名为 '-m' (move) , 但必须小心使用 '- M' , 因为它迫使重命名, 即使已经有一个已有的分支名称相同 。 以下是“ gitt- branch” man page的节录 :

采用-m或-m或-M选项,<oldbranch>将重新命名为<newbranch>。如果<oldbranch>具有相应的卷号, 重新命名为匹配<newbranch>,将创建一个重写条目以记住分支重新命名。如果<newbranch>存在, -M 必须用于强制重命名 。

仅三个步骤,以复制名称的更改remote以及基特胡卜人的故事:

步骤1git branch -m old_branchname new_branchname

步骤2git push origin :old_branchname new_branchname

步骤3git push --set-upstream origin new_branchname

重命名本地分支GitHub 桌面桌面,单击现任分处选项卡 (当前仓库右侧) , 右键单击您想要重命名的分支, 右键单击重命名 。 然后您会被弹出提示到可以重命名的位置 。

enter image description here

使用此命令重命名分支 :

git branch -m [old_branch_name] [new_branch_name]

-m:它重命名/移动分支。如果已经有一个分支,则会出错。

如果已经有一个分支, 您想要用该分支重命名, 请使用 :

 git rename -M [old_branch_name] [new_branch_name]

有关帮助的更多信息,请在终端中使用此命令 :

git branch --help

man git branch

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

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 分支名称这是一篇关于这个的好文章。