我如何重命名尚未被推到远程仓库的本地分支 ?
相关:
当前回答
实际上,你有三个步骤 因为本地分行服务器上有一个复制件 所以我们在服务器上的两个步骤上有一个步骤是本地分行:
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 <new_name>
git push origin :<old_name>
git push origin <new_name>:refs/heads/<new_name>
EDIT(12/01/2017):确保您运行命令git status
并检查新创建的分支指向的是它自己的参考文献,而不是旧的参考文献。如果找到旧分支的引用文献,您需要解开上游的设置,使用 :
git branch --unset-upstream
重命名当前分支 :
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>
可能正如其他人所提到的那样,这将是分支命名中出现的情况不匹配。
如果你有这样的情况,我可以猜测 你在Windows上,这也将导致你:
$ git branch -m CaseSensitive casesensitive
fatal: A branch named 'casesensitive' already exists.
然后,你必须做一个中间步骤:
$ git branch -m temporary
$ git branch -m casesensitive
仅此而已。
试图具体回答问题(至少是标题)。
您也可以重新命名当地当地树枝,但继续追踪遥控器上的旧名称。
git branch -m old_branch new_branch
git push --set-upstream origin new_branch:old_branch
现在,当你跑的时候git push
远程old_branch
ref 与您的本地更新new_branch
.
你必须知道并记住配置此配置。 但如果您没有选择远程分支名称的选择, 它可能会有用, 但是您不喜欢它( 我的意思是, 您有一个非常好也希望本地分行名称更明确。
使用抓取配置, 您甚至可以重命名本地远程引用 , 即refs/remote/origin/new_branch
ref 指向分支,事实上就是old_branch
上 年 月origin
然而,我非常不赞成这样做,因为你心智安全。
实际上,你有三个步骤 因为本地分行服务器上有一个复制件 所以我们在服务器上的两个步骤上有一个步骤是本地分行:
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>