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

相关:


当前回答

您的分支完成后, 重新命名分支将会有用 。 然后, 新的东西即将到来, 您想要在同一分支中开发, 而不是删除它, 然后创建新的分支 。

从我的经验来看,为了重新命名基特的一个本地和偏远分支,你应该采取以下步骤。

引引自多州 - 在 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

其他回答

重命名当前分支 :

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>

另一个选项是根本不使用命令行。 Git GUI 客户端,例如源树树导致像这个这样的问题 成为Stack overflow最受关注的问题之一。

在 SourceTree 中,右键单击左侧“ Branches” 窗格中的任何本地分支并选择“ 重命名... ” 。

在视觉演播室:

· 管理处 _______________________________________________________________________________________________________________________您的仓库您的分支重命名

git branch -m old_branch_name new_branch_name

上述命令将改变您的分支名称, 但你必须非常小心地使用重新命名的分支, 因为它仍然会指与其相关的旧的上游分支, 如果有的话 。

如果您想要在本地分支重新命名为新分支后将一些更改推入母版( 例如名称) :

git push origin new_branch_name:master(现在更改将转到母版分支, 但您的本地分支名称是新_ branch_ name)

详情见 " 。如何在 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