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

相关:


当前回答

有关这一程序的更多详情。

如何在 Git 中重命名本地分支

  • 要重命名当前分支, 请确认您已经检查过, 并且正在使用您想要重命名的分支 。
    git checkout oldbranch
    时当时
    git branch -m newbranch
  • 如果您想要,您可以在另一个分支工作时重新命名分支。
    git branch -m oldbranch newbranch

如何重命名 Git 中的远程分支

如果其他用户使用此分支并承诺执行此分支, 您应该在将其重新命名为本地之前将其拉动 。 这样可以确保您的本地仓库得到更新, 并确保其他用户所做的更改不会丢失 。

  • 首先,我们需要删除oldbranch从远程仓库中键,然后按enwbranch至远程。
    git push origin --delete oldbranch

  • 使用-u(固定上游)选项,
    git push origin -u newbranch

其他回答

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

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

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

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

重命名当前分支 :

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>

如果您不想将分支推到远程服务器, 这个示例将很有用 :

假设你有一个现有的分支 叫做"我的热能特长" 你想把它改名为"特长15"

首先,你想改变你的地方分支。

git branch -m my-hot-feature feature-15

更多信息,请访问地方和远程重命名Git的一个分支.

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

enter image description here