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

相关:

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


当前回答

可能正如其他人所提到的那样,这将是分支命名中出现的情况不匹配。

如果你有这样的情况,我可以猜测 你在Windows上,这也将导致你:

$ git branch -m CaseSensitive casesensitive
fatal: A branch named 'casesensitive' already exists.

然后,你必须做一个中间步骤:

$ git branch -m temporary
$ git branch -m casesensitive

仅此而已。

其他回答

吉特・伊特的反派命令 试试这个 对我有用

默认分支已被重新命名 ! { oldBranchName} 现在命名为{ newBranchName} 如果您有本地克隆, 您可以运行以下命令来更新它 。

git branch -m {oldBranchName} {NewBranchName}
git fetch origin
git branch -u origin/{NewBranchName} {NewBranchName}
git remote set-head origin -a

所有你必须做的是三步:

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

如果您不想将分支推到远程服务器, 这个示例将很有用 :

假设你有一个现有的分支 叫做"我的热能特长" 你想把它改名为"特长15"

首先,你想改变你的地方分支。

git branch -m my-hot-feature feature-15

若想了解更多信息,请访问Git的本地和远程重命名分部。

以下是重新命名分支的步骤 :

切换到需要重命名为 git 分支的分支 -m < new_ name> git 推力源 : <old_ name> git 推力源 < new_ name>:refs/heads/ < new_ name>

EDIT (12/01/2017): 确保您运行命令 Git 状态, 并检查新建的分支指向的是它自己的参考文献, 而不是旧的参考文献。 如果您发现旧的分支的引用, 您需要解开对上游的设置 :

git branch --unset-upstream

使用此命令重命名分支 :

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