美文网首页
Renaming the default branch from

Renaming the default branch from

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

    Renaming the default branch from master to main on Github.

    Overview

    Based on the suggestion by the Conservancy, GitHub renamed the master branch to main branch.
    To learn more about the changes, see The default branch for newly-created repositories is now main.

    Steps

    Rename local master branch

    git branch -m master main 
    

    Push main to remote repo

    git push -u origin main
    

    Update default branch on Github

    Open GitHub repository in the browser, click Settings -> Branches and change the default branch to main.

    image
    Or using 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"}'
    

    Delete master branch

    git push --delete origin master
    

    Changing the default for new local repositories

    git config --global init.defaultBranch main
    

    Using github-renaming

    github-renaming, renaming the default branch of our own repositories on GitHub easily.

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

    References

    相关文章

      网友评论

          本文标题:Renaming the default branch from

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