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

相关:


当前回答

之前所有的答案都在谈论git branch -m。 当然, 操作很容易, 但对我来说, 可能很难记住另一个 Git 命令 。 所以我试图完成我熟悉的指令。 是的, 你可能猜到了 。

我用的是git branch -b <new_branch_name>。如果你不想保存旧的分支,现在你可以执行git branch -D <old_branch_name>要删除它。

我知道这或许有点无聊, 但更容易理解和记住。我希望这对你有益。

其他回答

高级 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

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

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

git branch -m my_new_branch

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

git branch -m my_old_branch my_new_branch

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

Change branch name locally

如果您想要:

  • 重命名 Git 仓库, 运行 :git branch -m <oldname> <newname>
  • 删除旧分支 :git push origin: old-name new-name
  • 提交使用 :git commit <newname>
    • 并按下使用 :git push origin new_branch_name:master
  • 如果您想要检查状态, 请使用 :git status
  • 如果您想要检查退出, 请使用 :git checkout

您的分支完成后, 重新命名分支将会有用 。 然后, 新的东西即将到来, 您想要在同一分支中开发, 而不是删除它, 然后创建新的分支 。

从我的经验来看,为了重新命名基特的一个本地和偏远分支,你应该采取以下步骤。

引引自多州 - 在 Git 中重命名本地和远程分支

1. 重新命名您的本地分支

如果您在分支上, 您想要重命名 :

git branch -m new-name

如果在另一分支上:

git branch -m old-name new-name

2. 删除旧名称远程分支,并按下新名称本地分支

git push origin :old-name new-name

3. 重新设置新命名地方分支的上游分支

git push origin -u new-name

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

enter image description here