【问题标题】:git push renames branchgit push 重命名分支
【发布时间】:2016-05-20 08:22:36
【问题描述】:

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

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 重命名它的实例。

【问题讨论】:

    标签: git github repository rename


    【解决方案1】:

    即使您将 old_branch_name 的本地名称更改为 new_branch_name...

    您仍然需要推送old_branch_name 删除(在推送新名称之后),as seen here

    git push origin :<old_name>
    

    【讨论】:

      【解决方案2】:

      即使您将 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 是您希望本地分支跟踪的远程 分支的名称。

      【讨论】:

      • 这也是同样的事情。输出为* [new branch] new_branch -&gt; old_branch Branch new_branch set up to track remote branch old_branch from origin.
      猜你喜欢
      • 2011-10-28
      • 1970-01-01
      • 1970-01-01
      • 2011-09-29
      • 2011-06-12
      • 2013-08-25
      • 2010-11-18
      相关资源
      最近更新 更多