美文网首页
Github默认分支由master变更为main

Github默认分支由master变更为main

作者: 仇志飞 | 来源:发表于2021-07-28 16:43 被阅读0次

    Github默认分支由master变更为main.

    Overview

    https://tools.ietf.org/id/draft-knodel-terminology-00.html 影响, github 于 2020年10月1日后, 修改默认分支为 main, 详见The default branch for newly-created repositories is now main.

    Steps

    master 重命名为 main

    git branch -m master main 
    

    同步至远端

    git push -u origin main
    

    修改 Github 仓库默认分支

    浏览器打开 Github 仓库, 点击 Settings -> Branches 修改默认分支为 main.

    image
    或者使用 GitHub REST API.
    curl \
      -X PATCH \
      -H "Accept: application/vnd.github.v3+json" \
      -H "Authorization: token {access_token}" \
      https://api.github.com/repos/{owner}/{repo} \
      -d '{"default_branch":"main"}'
    

    删除旧的 master 分支

    git push --delete origin master
    

    修改本地 git init 默认分支

    git config --global init.defaultBranch main
    

    使用 github-renaming

    使用 github-renaming 可以更简单修改默认分支.

    gem install github-renaming
    github-renaming default-branch <old-branch> <new-branch> -t <token> -r <user/repo>
    

    References

    相关文章

      网友评论

          本文标题:Github默认分支由master变更为main

          本文链接:https://www.haomeiwen.com/subject/eoizmltx.html