我如何重命名尚未被推到远程仓库的本地分支 ?
相关:
重命名本地和远程 Git 仓库的主分支 ?
我如何重命名尚未被推到远程仓库的本地分支 ?
相关:
重命名本地和远程 Git 仓库的主分支 ?
当前回答
要重命名您的当前分支 :
git branch -m <newname>
其他回答
这里有三个步骤:命令, 您可以在终端内调用, 更改分支名称 。
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 分支名称是一个很好的文章 。
另一个选项是完全不使用命令行。 Git GUI 客户端, 如 SourceTree , 拿走了导致像此这样的问题成为Stack 溢流中最受关注的问题的学习周期曲线 / 疼痛 。
在 SourceTree 中,右键单击左侧“ Branches” 窗格中的任何本地分支并选择“ 重命名... ” 。
可能正如其他人所提到的那样,这将是分支命名中出现的情况不匹配。
如果你有这样的情况,我可以猜测 你在Windows上,这也将导致你:
$ git branch -m CaseSensitive casesensitive
fatal: A branch named 'casesensitive' already exists.
然后,你必须做一个中间步骤:
$ git branch -m temporary
$ git branch -m casesensitive
仅此而已。
高级 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 检出 - dumb- name
git 检出 -- -- -dumb-name
"s,'s和\s也没有帮助。 git 分支 -m不工作。
我终于把它修好了。 进入您的工作副本 . git/ refs/ heads, 找到文件名“ - dumb- name ” , 获取分支的大麻。 然后, 这将检查它, 制造一个新的有正常名称的分支, 并删除旧的分支 。
git checkout {hash}
git checkout -b brilliant-name
git branch -d -- -dumb-name