我如何重命名尚未被推到远程仓库的本地分支 ?
相关:
重命名本地和远程 Git 仓库的主分支 ?
我如何重命名尚未被推到远程仓库的本地分支 ?
相关:
重命名本地和远程 Git 仓库的主分支 ?
当前回答
这里有三个步骤:命令, 您可以在终端内调用, 更改分支名称 。
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 分支名称是一个很好的文章 。
其他回答
只要三步即可在远程和GitHub复制名称变化:
第 1 步 git 分支 - m 旧的Branchname new_ branchname
步骤 2 git 推进源 : old_ branchname new_ branchname
步骤 3 git 推进 - 设置上流源新分支名
要重命名本地分支 :
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 new-name
如果在另一分支上:
git branch -m old-name new-name
删除旧名称远程分支并按下新名称本地分支 。
git 推推源: old- name new- name
重置新命名本地分支的上游分支。 切换到分支, 然后 :
git 推进源 - u new- name
或者为了快速地做到这一点 你可以使用这三步:
# 本地重命名分支
git branch -m old_branch new_branch
# 删除旧的远程分支
git push origin :old_branch
# 推动新分支, 设置本地分支以跟踪新远程
git push --set-upstream origin new_branch
参考文献:https://www.w3docs.com/snippets/git/how-to-rename-git-local-and-remote-branches.html
所有你必须做的是三步:
在.git/refs/head 下给旧分支以.git/refs/head 下的新名称 给旧分支以.git/log/refs/head 下的新名称 更新 .git/HEAD 以导致您的新分支名称 。