我正在尝试使用重命名项目的分支
git branch -m old_branch_name new_brach_name
重命名本地分支,效果很好,本地分支被重命名。但是从远程(在 github 上或在 git shell 中)删除旧分支名称并使用
git push origin new_branch_name
我得到这个输出
Counting objects: 92, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (60/60), done.
Writing objects: 100% (92/92), 488.48 KiB | 0 bytes/s, done.
Total 92 (delta 3), reused 0 (delta 0)
To https://github.com/<username>/<repo_name>.git
* [new branch] new_branch_name -> old_branch_name
旧的分支名称仍然显示在远程和 github 上。
什么给了?我在这里用谷歌搜索并搜索了很多,我找不到其他人重命名分支并在将其推送到远程时让 git 将其重命名回来的实例。
最佳答案
即使您将 old_branch_name
的本地名称更改为 new_branch_name
,此本地分支仍在跟踪 GitHub 上的相同远程分支(或无论你的存储库在哪里)。为了告诉 Git 你希望这个本地分支跟踪不同的远程分支,你需要明确告诉它新的本地分支也有一个新的上游位置:
git checkout new_branch_name
git push --set-upstream origin new_branch_name
在上面的 git push
命令中,new_branch_name
是您希望本地分支跟踪的远程分支的名称。
关于git push 重命名分支,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35307480/