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

相关:


当前回答

在PhpStorm中:

VCS你的支节重命名

其他回答

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

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

所有你必须做的是三步:

  1. 给旧分支下.git/refs/heads新名称
  2. 给旧分支下.git/logs/refs/heads新名称
  3. 更新.git/HEAD导致您新分支名称

重命名当前分支 :

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>
  1. 重新命名您的本地分支 。

如果您在分支上, 您想要重命名 :

git branch -m new-name

如果在另一分支上:

git branch -m old-name new-name
  1. 删除旧名称远程分支并按下新名称本地分支 。

git push origin :old-name new-name

  1. 重置新命名本地分支的上游分支。 切换到分支, 然后 :

git push origin -u new-name

或者为了快速地做到这一点 你可以使用这三步:

# 本地重命名分支

git branch -m old_branch new_branch  

# 删除旧的远程分支

git push origin :old_branch  

# 推动新分支, 设置本地分支以跟踪新远程

git push --set-upstream origin new_branch   

参考:https://www.w3docs.com/snippets/git/how-to-rename-git-local-and-remote-branches.html

可能正如其他人所提到的那样,这将是分支命名中出现的情况不匹配。

如果你有这样的情况,我可以猜测 你在Windows上,这也将导致你:

$ git branch -m CaseSensitive casesensitive
fatal: A branch named 'casesensitive' already exists.

然后,你必须做一个中间步骤:

$ git branch -m temporary
$ git branch -m casesensitive

仅此而已。