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

相关:


当前回答

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

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

其他回答

如果您愿意使用源树树你可以右键单击分支并选择“改名 ” 。

enter image description here

重命名当前分支 :

git branch -m <newname>

将指定给任何分支的分支重新命名 :

git branch -m <oldname> <newname>

-m短为--move.


推动地方分支并重设上游分支:

git push origin -u <newname>

删除远程分支 :

git push origin --delete <oldname>

创建git rename别名 :

git config --global alias.rename 'branch -m'

在 Windows 或其他不区分大小写的文件系统上使用-M如果名称仅出现资本化变化, 则该名称只有资本化变化 。 否则, Git 将投"部门已经存在"错误 。

git branch -M <newname>

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

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

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

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

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

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

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