GitHub/Changing Default Branch: Difference between revisions

From MozillaWiki
Jump to navigation Jump to search
m (fix typo)
(truncating content as we transition ownership from IT to CloudEng)
 
Line 1: Line 1:
There are many good reasons to rename the default branch for your repository. GitHub gives some of the reasons and [https://github.com/github/renaming/ provides guidance] for the procedure.
'''2026-10-07: GitHub Enterprise ownership has been transitioned from IT to CloudEng.''' Customer documentation has been moved to [https://mozilla-hub.atlassian.net/wiki/spaces/GHE/pages/3087892663/Getting+help+with+GitHub Getting help with GitHub] in Confluence. Please update any links to this page accordingly. If you are an external contributor, please reach out to your sponsor in the appropriate [https://chat.mozilla.org/ Matrix channel] for support.


However, if your repository has been in use for a while, everyone who has clones of the repository must update their clones to properly reflect the change. GitHub will add messages to the output of git commands to inform folks, but it is very easy to miss those. If the per-clone changes are not made, then the branch could accidentally be re-created with old contents. The procedure below provides a workaround, which can be enabled by a repository admin.
This content has been moved to: https://docs.github.com/en/repositories/configuring-branches-and-merges-in-your-repository/managing-branches-in-your-repository/renaming-a-branch
 
1. Rename the default branch, following [https://github.com/github/renaming/#renaming-existing-branches GitHub's instructions].
 
2. Create a branch protection rule for the old branch name ([https://docs.github.com/en/github/administering-a-repository/about-protected-branches instructions]). Make sure the following checks are enabled:
* [https://docs.github.com/en/github/administering-a-repository/about-protected-branches#require-pull-request-reviews-before-merging Require pull request reviews before merging] - any number is fine
* [https://docs.github.com/en/github/administering-a-repository/about-protected-branches#require-status-checks-before-merging Require status checks before merging]
* [https://docs.github.com/en/github/administering-a-repository/about-protected-branches#include-administrators Include administrators]
 
3. Unfortunately, that branch protection rule doesn't apply until the 2nd commit to the old branch name. So make an unrelated first commit:
        mkdir /tmp/rename
        cd /tmp/rename
        touch do_not_use_this_branch_name
        echo "Do not use this branch name!" > README.md
        git init
        git add --all
        git commit -m "Block commits to this branch name on GitHub"
        git push git@github.com:$OWNER/$REPOSITORY HEAD:refs/heads/$OLD_BRANCH_NAME
4. Review any CI configurations that may refer to the old branch name, and update as needed.

Latest revision as of 21:22, 7 October 2026

2026-10-07: GitHub Enterprise ownership has been transitioned from IT to CloudEng. Customer documentation has been moved to Getting help with GitHub in Confluence. Please update any links to this page accordingly. If you are an external contributor, please reach out to your sponsor in the appropriate Matrix channel for support.

This content has been moved to: https://docs.github.com/en/repositories/configuring-branches-and-merges-in-your-repository/managing-branches-in-your-repository/renaming-a-branch