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

相关:


当前回答

git branch -m [old-branch] [new-branch]

-m 意指全部从[旧部门]移动到[新部门],并记住您可以使用 -M 用于其他文件系统。

其他回答

高级 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 <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 branch -m old_branch new_branch
git push --set-upstream origin new_branch:old_branch

现在,当你跑的时候git push远程old_branchref 与您的本地更新new_branch.

你必须知道并记住配置此配置。 但如果您没有选择远程分支名称的选择, 它可能会有用, 但是您不喜欢它( 我的意思是, 您有一个非常好也希望本地分行名称更明确。

使用抓取配置, 您甚至可以重命名本地远程引用 , 即refs/remote/origin/new_branchref 指向分支,事实上就是old_branch上 年 月origin然而,我非常不赞成这样做,因为你心智安全。

一个简单的方法来做到这一点:

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 分支 - m 新名称