我如何重命名尚未被推到远程仓库的本地分支 ?
相关:
当前回答
可能正如其他人所提到的那样,这将是分支命名中出现的情况不匹配。
如果你有这样的情况,我可以猜测 你在Windows上,这也将导致你:
$ git branch -m CaseSensitive casesensitive
fatal: A branch named 'casesensitive' already exists.
然后,你必须做一个中间步骤:
$ git branch -m temporary
$ git branch -m casesensitive
仅此而已。
其他回答
另一个选项是根本不使用命令行。 Git GUI 客户端,例如源树树导致像这个这样的问题 成为Stack overflow最受关注的问题之一。
在 SourceTree 中,右键单击左侧“ Branches” 窗格中的任何本地分支并选择“ 重命名... ” 。
实际上,你有三个步骤 因为本地分行服务器上有一个复制件 所以我们在服务器上的两个步骤上有一个步骤是本地分行:
git branch -m <old-branch-name> <new-branch-name>
git push <remote-name[origin by default]> :<old-branch-name>
git push -u <new-branch-name>
要重命名本地分支 :
git branch -m [old-branch] [new-branch]
现在你也必须在远程服务器上传播这些变化。
将已删除的旧分支的更改推到下方 :
git push origin :[old-branch]
推动新分支创建的变更 :
git push origin [new-branch]
如果您不想将分支推到远程服务器, 这个示例将很有用 :
假设你有一个现有的分支 叫做"我的热能特长" 你想把它改名为"特长15"
首先,你想改变你的地方分支。
git branch -m my-hot-feature feature-15
更多信息,请访问地方和远程重命名Git的一个分支.
重命名本地分支 :
git branch -m <old_branch_name> <new_branch_name>
按下新分支 :
git push --set-upstream origin <new_branch_name>