【问题标题】:Unable to rename git branch to "master", pushes to remote with incorrect name无法将 git 分支重命名为“master”,以错误的名称推送到远程
【发布时间】:2016-09-12 05:50:41
【问题描述】:

使用this SO 帖子作为参考,我能够将我的master 重命名为v1,现在我想将我的v2 分支重命名为master。我已经从 GitHub 将默认分支更改为 v1,但是当我尝试将 v2 重命名为 master 时,本地分支重命名很好,但由于某种原因,它将 v2 名称推送到远程。这是命令行会话:

Microsoft Windows [Version 10.0.10586]
(c) 2015 Microsoft Corporation. All rights reserved.

C:\Users\Mahi\Documents\GitHub\EasyPlayer>git branch
  v1
* v2

C:\Users\Mahi\Documents\GitHub\EasyPlayer>git branch -m master

C:\Users\Mahi\Documents\GitHub\EasyPlayer>git branch
* master
  v1

C:\Users\Mahi\Documents\GitHub\EasyPlayer>git push origin :v2
To https://github.com/Mahi/EasyPlayer.git
 - [deleted]         v2

C:\Users\Mahi\Documents\GitHub\EasyPlayer>git push origin master
Counting objects: 39, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (19/19), done.
Writing objects: 100% (39/39), 8.17 KiB | 0 bytes/s, done.
Total 39 (delta 9), reused 39 (delta 9)
To https://github.com/Mahi/EasyPlayer.git
 * [new branch]      master -> v2

C:\Users\Mahi\Documents\GitHub\EasyPlayer>

如何正确地将我的 v2 分支重命名为 master

【问题讨论】:

    标签: git github version-control branch git-branch


    【解决方案1】:

    尝试强制本地/远程分支关联:

    git push -u origin master:master
    

    该分支的本地配置可能仍将 v2 作为其上游分支。上面的命令行应该重置它。

    【讨论】:

    • 非常感谢! :) 非常感谢您添加的解释,起初我不知道为什么该命令有效
    猜你喜欢
    • 2012-07-25
    • 1970-01-01
    • 1970-01-01
    • 2015-08-14
    • 2011-10-28
    • 2018-12-03
    • 2020-09-16
    • 2020-02-05
    • 2015-08-15
    相关资源
    最近更新 更多