如何将GIT项目从使用Master作为MAIN的默认分支迁移?
我是在Github/Gitlab上托管的项目的维护者,该项目有许多贡献者。我想从使用Master
作为默认分支到main
。我该怎么做而不弄乱?
我已经阅读了有关该主题的一些博客 - 但希望在Stackoverflow上进行讨论,其中评论可能会指出一个人可能会忽略的问题。
I'm the maintainer of a project that's hosted on github/gitlab which has a number of contributors. I want to migrate from using master
as the default branch to main
. How do I do that without messing up?
I've read some blog-posts on the topic, but would prefer a discussion over here at StackOverflow where comments might point out issues that a single person could have overlooked.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Github提供了一个迁移选项,因此很琐碎。但是,即使有任何其他服务(例如Gitlab)还没有类似的东西,只要您执行正确的步骤,至少从技术的角度来看,它相对简单。
无论哪种方式,除非您的项目很小,否则最大的麻烦肯定会让您的所有贡献者正确地将修复程序正确地应用于进行中。
您需要做的
github
在项目页面上,导航到
设置
,在“默认分支”部分中,按编辑按钮,然后从Master更改它
Main
。gitlab,又名手动迁移
我假设您的远程/上游称为
onecount
- 如果称为“不同的事物”在所有命令中。Master
重命名为main
,然后将其推到上游:告诉您的上游,
main
是新默认值:设置/存储库
,“默认分支”,选择main
,然后按“保存更改”。然后,在同一页面上,转到“受保护分支”部分,然后保护main
和UnprotectMaster
,然后按“保存更改”。删除
Master
上游 - 并不是严格必要的,但确实减少了混乱:master
要将其推入main
main < /代码>而不是:master
”。将下拉纸从Master
更改为main
。据我所知,您的合作者/同事需要做的事情
- 就是这样 -
&amp;&amp;
s是一个好主意,以防万一某些东西加起来。如果您在此建议下遇到问题,请发表评论。
git
fuckups对解开而言,所以我们至少可以做的就是尝试并不重塑轮子比我们需要的要多。Github offers a migration option, so it's trivial. But even with any other service like gitlab that doesn't have something like that (yet), as long as you're doing the right steps it's relatively straight-forward, at least from a technical point of view.
Either way, unless your project is quite small, the biggest hassle will surely be getting all your contributors to apply fixes to work-in-progress correctly.
What you need to do
Github
On your project page, navigate to
settings
, and in the section "Default branch", press the edit button and change it frommaster
tomain
.Gitlab, aka migrating manually
I'm assuming that your remote/upstream is called
origin
- if it's called something different, replaceorigin
with that name in all commands accordingly.master
tomain
, and push it upstream:Tell your upstream that
main
is the new default:settings/repository
, section "Default branch", selectmain
and press "Save Changes". Then, on the same page, go the the section "Protected branches", and protectmain
and unprotectmaster
, and press "Save Changes".Delete
master
on upstream - not strictly necessary, but does reduce confusion:master
to be pushed intomain
instead:master
". Change the drop-down frommaster
tomain
.What your collaborators/colleagues need to do
As far as I know, that's it - the
&&
s are a good idea to protect you in case something doesn't add up.Please leave a comment if you ran into issues following this advice.
git
fuckups are hellish to untangle, so the least we can do is to try and not reinvent the wheel any more than we need to.我正在管理一个自托管的gitlab实例(v13.xy),而您不必手动进行操作 - 与Arne for Github提到的那样,它也有类似的解决方案。
首先,将您的主分支复制到主分支。
然后,转到Project
设置
,单击存储库
,然后更改默认分支。之后,您可以使用上面的片段更新本地存储库(如果需要的话,请更改分支名称),或者如果您担心自己可能会弄乱某些东西,则可以删除项目并再次克隆。
I'm managing a self-hosted gitlab instance (v13.x.y), and you don't have to do it manually - there's a similar solution to this as the one mentioned by Arne for github.
First, copy your master branch to main branch.
Then, go to project
Settings
, clickRepository
, and change the default branch.After that, you can use the above snippet to update your local repository (change the branch names if you need to), or if you're worried that you might mess something up, you can delete the project and clone it again.