git push 重命名分支

标签 git github repository rename

我正在尝试使用重命名项目的分支

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/

相关文章:

git - 上传文件而不跟踪 Git 中的更改

Git checkout --补丁

git - TortoiseGit:无法使用 SSH 在 VPS 上 Git 克隆私有(private)存储库

git - 我需要获取 git repo 的分支列表,而无需在我的本地机器上克隆 repo

git - 在 git revert 中给 -m 开关赋予什么值?

sql - 无法将 SQL 文件添加到 Git 存储库?

java - 将 Maven Central 托管的 JAR 添加到本地 .m2 存储库的 mvn 命令 (CLI) 是什么

ant - 无法让 Apache Ivy 不从 Spring 存储库下载源代码

node.js - Heroku 部署错误 : Cannot find module './errors/cast'

git - Gerrit + GitLab 的 CI