The closest thing to renaming is deleting and then re-creating on the remote.
(与重命名最接近的是删除,然后在远程上重新创建。)
For example: (例如:)
git branch -m master master-old
git push remote :master # delete master
git push remote master-old # create master-old on remote
git checkout -b master some-ref # create a new local master
git push remote master # create master on remote
However this has a lot of caveats.
(但是,这有很多警告。)
First, no existing checkouts will know about the rename - git does not attempt to track branch renames. (首先,没有现成的检出会了解重命名- Git 并不试图跟踪分支重命名。)
If the new master
doesn't exist yet, git pull will error out. (如果新的master
服务器不存在,则git pull将出错。)
If the new master
has been created. (是否创建了新的master
。)
the pull will attempt to merge master
and master-old
. (拉将尝试合并master
和master-old
。)
So it's generally a bad idea unless you have the cooperation of everyone who has checked out the repository previously. (因此,除非您与先前签出了存储库的所有人进行合作,否则通常这是一个坏主意。)
Note: Newer versions of git will not allow you to delete the master branch remotely by default.
(注意:默认情况下,较新版本的git不允许您远程删除master分支。)
You can override this by setting the receive.denyDeleteCurrent
configuration value to warn
or ignore
on the remote repository. (您可以通过将receive.denyDeleteCurrent
配置值设置为warn
或ignore
远程存储库来覆盖此设置。)
Otherwise, if you're ready to create a new master right away, skip the git push remote :master
step, and pass --force
to the git push remote master
step. (否则,如果您准备立即创建新的master,则跳过git push remote :master
步骤,并将--force
传递给git push remote master
步骤。)
Note that if you're not able to change the remote's configuration, you won't be able to completely delete the master branch! (请注意,如果您无法更改遥控器的配置,则将无法完全删除master分支!)
This caveat only applies to the current branch (usually the master
branch);
(此警告仅适用于当前分支(通常是master
分支);)
any other branch can be deleted and recreated as above. (可以如上所述删除和重新创建任何其他分支。)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…