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

相关:

重命名本地和远程 Git 仓库的主分支 ?


当前回答

在视觉演播室:

Git 管理分支 支部 你的仓库 你的支部 重命名

其他回答

要重命名当前分支( 除独立 HEAD 状态外) 您也可以使用此别名 :

[alias]
    mvh = !sh -c 'git branch -m `git rev-parse --abbrev-ref HEAD` $1'

如果您想要更改当前分支的名称,请运行 :

git branch -m [old_branch] [new_branch]

如果您想要删除旧的远程分支,请运行 :

git push origin :[old_branch]

如果您想要删除旧的远程分支并创建一个新的远程分支,请运行 :

git push origin :old_branch new_branch

所有你必须做的是三步:

在.git/refs/head 下给旧分支以.git/refs/head 下的新名称 给旧分支以.git/log/refs/head 下的新名称 更新 .git/HEAD 以导致您的新分支名称 。

如果您愿意使用 SourceTree (我强烈建议), 您可以右键单击分支并选择“ 改名 ” 。

使用此命令重命名分支 :

git branch -m [old_branch_name] [new_branch_name]

- m: 它重命名/ 移动分支。 如果已经有一个分支, 您将会出错 。

如果已经有一个分支, 您想要用该分支重命名, 请使用 :

 git rename -M [old_branch_name] [new_branch_name]

有关帮助的更多信息,请在终端中使用此命令 :

git branch --help

man git branch