我如何重命名尚未被推到远程仓库的本地分支 ?
相关:
重命名本地和远程 Git 仓库的主分支 ?
我如何重命名尚未被推到远程仓库的本地分支 ?
相关:
重命名本地和远程 Git 仓库的主分支 ?
当前回答
git branch -m old_branch_name new_branch_name
上述命令将改变您的分支名称, 但你必须非常小心地使用重新命名的分支, 因为它仍然会指与其相关的旧的上游分支, 如果有的话 。
如果您想要在本地分支重新命名为新分支后将一些更改推入母版( 例如名称) :
git push 源新\ branch_ name : master (现在更改将转到母版分支, 但您本地的分支名称是新_ branch_ name )
详情请见“如何在 Git 中重新命名您的本地分支名称 ” 。
其他回答
如果您想要更改分支的名称
git branch -m newname
改变本地分支很容易...
如果您在树枝上, 您想要更改名称, 只需这样做 :
git branch -m my_new_branch
否则,如果你是主人 或任何其他分支 除了你想改名的分支, 简单做:
git branch -m my_old_branch my_new_branch
另外,我在下面创建图像, 以在命令行的操作中显示此图像。 在这种情况下, 您在主分支中, 例如 :
调
要重命名本地分支 :
git branch -m [old-branch] [new-branch]
现在你也必须在远程服务器上传播这些变化。
将已删除的旧分支的更改推到下方 :
git push origin :[old-branch]
推动新分支创建的变更 :
git push origin [new-branch]
另一个选项是完全不使用命令行。 Git GUI 客户端, 如 SourceTree , 拿走了导致像此这样的问题成为Stack 溢流中最受关注的问题的学习周期曲线 / 疼痛 。
在 SourceTree 中,右键单击左侧“ Branches” 窗格中的任何本地分支并选择“ 重命名... ” 。
一个简单的方法来做到这一点:
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
更多,看看这个。