我如何重命名尚未被推到远程仓库的本地分支 ?
相关:
重命名本地和远程 Git 仓库的主分支 ?
我如何重命名尚未被推到远程仓库的本地分支 ?
相关:
重命名本地和远程 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 old_branch new_branch
git push --set-upstream origin new_branch:old_branch
现在,当您运行 Git 推时, 远程的老管区ref 用您的本地新管区更新 。
您必须知道并记住这个配置。 但如果您没有选择远程分支名称的选择, 它可能会有用, 但是您不喜欢它( 您有一个很好的理由不喜欢它! ) 并且更喜欢您本地分支更清晰的名称 。
使用抓取配置, 您甚至可以重命名本地远程参考 。 也就是说, 拥有分支的 refs/ remote/ broot/ new_ branch ref 指针, 事实上就是原发的旧分队。 但是, 我非常不鼓励您这样做, 以保障您心灵的安全 。
重命名当前分支 :
git branch -m <newname>
将指定给任何分支的分支重新命名 :
git branch -m <oldname> <newname>
- M是短的 -移动。
推动地方分支并重设上游分支:
git push origin -u <newname>
删除远程分支 :
git push origin --delete <oldname>
要创建 git 重命名别名 :
git config --global alias.rename 'branch -m'
在 Windows 或其他不区分大小写的文件系统上, 如果名称中仅出现大小写变化, 请使用 - M 。 否则, Git 会丢弃一个“ 分支已经存在” 错误 。
git branch -M <newname>
您的分支完成后, 重新命名分支将会有用 。 然后, 新的东西即将到来, 您想要在同一分支中开发, 而不是删除它, 然后创建新的分支 。
从我的经验来看,为了重新命名基特的一个本地和偏远分支,你应该采取以下步骤。
从多个国家引出 - 在 Git 中重命名本地和远程分支
1. 重新命名您的本地分支
如果您在分支上, 您想要重命名 :
git branch -m new-name
如果在另一分支上:
git branch -m old-name new-name
2. 删除旧名称远程分支,并按下新名称本地分支
git push origin :old-name new-name
3. 重新设置新命名地方分支的上游分支
git push origin -u new-name
可能正如其他人所提到的那样,这将是分支命名中出现的情况不匹配。
如果你有这样的情况,我可以猜测 你在Windows上,这也将导致你:
$ git branch -m CaseSensitive casesensitive
fatal: A branch named 'casesensitive' already exists.
然后,你必须做一个中间步骤:
$ git branch -m temporary
$ git branch -m casesensitive
仅此而已。
所有你必须做的是三步:
在.git/refs/head 下给旧分支以.git/refs/head 下的新名称 给旧分支以.git/log/refs/head 下的新名称 更新 .git/HEAD 以导致您的新分支名称 。