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

相关:

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


当前回答

要重命名本地分支 :

git branch -m [old-branch] [new-branch]

现在你也必须在远程服务器上传播这些变化。

将已删除的旧分支的更改推到下方 :

git push origin :[old-branch]

推动新分支创建的变更 :

git push origin [new-branch]

其他回答

在视觉演播室:

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 branch -m <newname>

高级 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/refs/head 下给旧分支以.git/refs/head 下的新名称 给旧分支以.git/log/refs/head 下的新名称 更新 .git/HEAD 以导致您的新分支名称 。