我如何重命名尚未被推到远程仓库的本地分支 ?
相关:
当前回答
如果您愿意使用源树树你可以右键单击分支并选择“改名 ” 。
其他回答
所有你必须做的是三步:
.git/refs/heads
新名称.git/logs/refs/heads
新名称.git/HEAD
导致您新分支名称重命名本地分支GitHub 桌面桌面,单击现任分处选项卡 (当前仓库右侧) , 右键单击您想要重命名的分支, 右键单击重命名 。 然后您会被弹出提示到可以重命名的位置 。
这里有三个步骤:命令, 您可以在终端内调用, 更改分支名称 。
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 分支名称这是一篇关于这个的好文章。
如果您在分支上, 您想要重命名 :
git branch -m new-name
如果在另一分支上:
git branch -m old-name new-name
git push origin :old-name new-name
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
git branch -m old_branch_name new_branch_name
上述命令将改变您的分支名称, 但你必须非常小心地使用重新命名的分支, 因为它仍然会指与其相关的旧的上游分支, 如果有的话 。
如果您想要在本地分支重新命名为新分支后将一些更改推入母版( 例如名称) :
git push origin new_branch_name:master
(现在更改将转到母版分支, 但您的本地分支名称是新_ branch_ name)
详情见 " 。如何在 Git 中重新命名您的本地分支名称."