我如何重命名尚未被推到远程仓库的本地分支 ?
相关:
当前回答
所有你必须做的是三步:
.git/refs/heads
新名称.git/logs/refs/heads
新名称.git/HEAD
导致您新分支名称其他回答
一个简单的方法来做到这一点:
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 branch -m new_name
如果它是另一个分支, 您想要重命名
git branch -m old_name new_name
- 如果您的分支被推动, 那么在重新命名后, 您需要从远程 Git 仓库删除它, 并要求您的新本地端跟踪新的远程分支 :
git push origin :old_name
git push --set-upstream origin new_name
之前所有的答案都在谈论git branch -m
。 当然, 操作很容易, 但对我来说, 可能很难记住另一个 Git 命令 。 所以我试图完成我熟悉的指令。 是的, 你可能猜到了 。
我用的是git branch -b <new_branch_name>
。如果你不想保存旧的分支,现在你可以执行git branch -D <old_branch_name>
要删除它。
我知道这或许有点无聊, 但更容易理解和记住。我希望这对你有益。
对于 Git GUI 用户来说,它不可能简单得多。 在 Git GUI 中, 从“ 重新命名分支” 对话框创建的“ 重新命名分支” 对话框的向下列表中选择分支名称 : 重新命名, 输入新名称, 单击“ 重新命名 ” 。 我已经突出显示要在哪里找到向下下载列表 。
git branch -m old_branch_name new_branch_name
上述命令将改变您的分支名称, 但你必须非常小心地使用重新命名的分支, 因为它仍然会指与其相关的旧的上游分支, 如果有的话 。
如果您想要在本地分支重新命名为新分支后将一些更改推入母版( 例如名称) :
git push origin new_branch_name:master
(现在更改将转到母版分支, 但您的本地分支名称是新_ branch_ name)
详情见 " 。如何在 Git 中重新命名您的本地分支名称."