git-重命名所有默认分支
我使用gitlab进行源控制。 Gitlab最近将使用main
切换为新存储库的默认分支,如上所述在这里,这很好,我已经调整了我的开发环境以匹配。
我也想更改现有的存储库。 <步骤和仅一次用于一个存储库,更不用说复制历史的步骤了。由于我们的代码库由数百个存储库组成,因此这是不可行的。
有没有办法在Gitlab或Gitbash中自动化这一点?
I use Gitlab for source control. Gitlab recently made the switch to using main
as the default branch for new repositories, as described here, which is fine, and I've adjusted my development environments to match.
I would like to change my existing repositories as well. This tutorial describes a way to do this, but involves multiple manual steps and only works on one repository at a time, not to mention the steps of copying over history. As our code base is comprised of hundreds of repositories, this is just not feasible.
Is there a way to automate this in Gitlab or Gitbash?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这只是从 master 创建一个名为
main
的新分支,删除 master 分支,并调整默认/受保护分支规则的问题。这些操作可以使用 GitLab API 执行,它允许您编写这些操作的脚本。基本步骤和 API 参考:
使用 创建分支 API 从 master 创建
main
分支使用编辑项目API 设置默认分支到
main
使用保护分支API 保护
主要
(可选)使用 取消保护分支 API 删除 master 的保护和/或使用 删除分支 API 以删除 master 分支。
当然,您必须拥有足够的权限才能在项目中执行所有这些操作。
最后,您还可以使用列出项目 API列出所有项目并循环结果以将其应用到所有项目 - 您可以为每个项目编写一个类似
的脚本; 执行步骤 1-4
使用
python-gitlab< /code> 库
,像这样的脚本应该可以正确执行所有这些步骤:
This is just a matter of creating a new branch from master called
main
, deleting the master branch, and adjusting the default/protected branches rules. These operations can be performed using the GitLab API, which would allow you to script these actions.Basic steps and API references:
Use the create branch API to create the
main
branch from masterUse the edit project API to set the default branch to
main
use the protect branch API to protect
main
(optionally) use the unprotect branch API to remove protections from master and/or use the delete branch API to remove the master branch.
You must, of course, have sufficient permissions to take all these actions in the project.
Finally, you can also use the list projects API to list all of your projects and loop over the results to apply this to all your projects -- you can write a script like
for each project; do steps 1-4
Using the
python-gitlab
library, a script like this should be about right to do all those steps: