Master to main
This page tries to, briefly, show all the changes required to rename any branch from master to main in general. Aimed for the Moodle Community, to facilitate the transitions of all their awesome patches, plugins and integration, although, generic enough for anybody needing to rename any branch.
Moving from master to main for canonical/origin github based repositories
Note that these steps are valid for all the repositories @ GitHub. That includes both the "canonical/origin/upstream" ones and, also, all the clones of them that any developer/contributor may have.
- Go to your repo, click on "Settings"
- In the "General" settings page, near "Default branch" click on the pencil icon.
- Rename
mastertomain(all associated pull requests will be migrated, also any protection rules and other bits. See https://github.com/github/renaming for more information. - Time to hack (see the section)
Moving from master to main for other canonical/origin (gitlab, bitbucket, sourceforge, ...) repositories
Check if the repo supports renaming branches (similar to GitHub) or no. And verify if the utility allows the old
masterto continue working and if associated pull/merge requests and other settings are automatically moved or no.If the rename utility exists and suits your needs, use it (and skip next point).
In general, if there isn't any rename tool, the way to proceed manually is to:
Fetch all changes from remote and ensure that
masteris up to date.git fetch --all --prune && git fetch origin master:masterCreate locally the
mainbranch frommaster.git branch main masterPush the new branch upstream.
git push origin mainIn the canonical repo, configure everything to point to the new
mainbranch (rules, default branch...). Don't forget to analyse what happens with ongoing pull/merge requests that may be pointing tomaster.Once 100% sure that
mainis ok, remove the, now old,masterbranch.git push origin :masterIt's recommended to create a new issue in the repository (link to example), explaining the move from
mastertomain, so everybody that is subscribed or involved gets notified. Feel free to point to this document for details.
Time to hack (see the section).
Time to hack
Let's move any master occurrence/dependency in the codebase to main (link to example).
- For sure that includes any Travis/GHA... CI integrations. And any other external tool (
codecov,packagist...) that is being used. - If your codebase has any other hard-coded
masterdependency (not the best idea, but) ... it will need to be analysed and fixed too. - Apply changes (push, PR/MR, whatever...) ASAP.
Moving from master to main in your local clones
Fetch all changes from remote (that has been just renamed upstream).
git fetch --all --pruneRename the local branch from
mastertomain.git branch -m master mainPoint the local
mainbranch to the remotemainone (assuming that the canonical remote is namedoriginin your clone).git branch -u origin/main mainAdjust your local current HEAD, that still is pointing to the, now gone,
masterbranch.git remote set-head origin -aVerify that your local clone looks ok (so you can check your actual local branches and which remote/branch they are tracking now).
git branch -vvv