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

相关:


当前回答

在视觉演播室:

· 管理处 _______________________________________________________________________________________________________________________您的仓库您的分支重命名

其他回答

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

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

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

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

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

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

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

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

enter image description here

将当前分支重命名为新分支名称 :

git branch -m <new_name>

这将为您正在工作的当前分支设定新名称 。


要重命名另一个分支 :

git branch -m <old_name> <new_name>

您必须在此提供旧的分支名称和新分支名称 。