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

相关:


当前回答

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

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

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 <newname>

吉特・伊特的反派命令 试试这个 对我有用

默认分支已被重新命名 ! { oldBranchName} 现在命名为{ newBranchName} 如果您有本地克隆, 您可以运行以下命令来更新它 。

git branch -m {oldBranchName} {NewBranchName}
git fetch origin
git branch -u origin/{NewBranchName} {NewBranchName}
git remote set-head origin -a

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

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

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

2.9.2 Git 版本

如果您想要更改本地分支的名称, 请在 :

git branch -m new_name

如果您想要更改另一分支的名称 :

git branch -m old_name new_name

如果您想要将其它分支的名称更改为已经存在的名称 :

git branch -M old_name new_name_that_already_exists

注意: 最后一个命令是破坏性的, 将会重新命名您的分支, 但是您会丢失旧分支, 并且会丢失旧分支, 因为分支名称必须是独一无二的 。