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

相关:


当前回答

一个简单的方法来做到这一点:

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

更多信息这笔.

其他回答

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

步骤1git branch -m old_branchname new_branchname

步骤2git push origin :old_branchname new_branchname

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

要重命名您的当前分支 :

git branch -m <newname>

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

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

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

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

git branch -m my_new_branch

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

git branch -m my_old_branch my_new_branch

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

Change branch name locally

试图具体回答问题(至少是标题)。

您也可以重新命名当地当地树枝,但继续追踪遥控器上的旧名称。

git branch -m old_branch new_branch
git push --set-upstream origin new_branch:old_branch

现在,当你跑的时候git push远程old_branchref 与您的本地更新new_branch.

你必须知道并记住配置此配置。 但如果您没有选择远程分支名称的选择, 它可能会有用, 但是您不喜欢它( 我的意思是, 您有一个非常好也希望本地分行名称更明确。

使用抓取配置, 您甚至可以重命名本地远程引用 , 即refs/remote/origin/new_branchref 指向分支,事实上就是old_branch上 年 月origin然而,我非常不赞成这样做,因为你心智安全。