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

相关:


当前回答

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

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 <oldname> <newname>
  • 删除旧分支 :git push origin: old-name new-name
  • 提交使用 :git commit <newname>
    • 并按下使用 :git push origin new_branch_name:master
  • 如果您想要检查状态, 请使用 :git status
  • 如果您想要检查退出, 请使用 :git checkout

使用此命令重命名分支 :

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 用户可以手动重命名 :

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

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

enter image description here

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

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

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