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
master
tomain
(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
master
to 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
master
is up to date.git fetch --all --prune && git fetch origin master:master
-
Create locally the
main
branch frommaster
.git branch main master
-
Push the new branch upstream.
git push origin main
-
In the canonical repo, configure everything to point to the new
main
branch (rules, default branch...). Don't forget to analyse what happens with ongoing pull/merge requests that may be pointing tomaster
. -
Once 100% sure that
main
is ok, remove the, now old,master
branch.git push origin :master
-
It's recommended to create a new issue in the repository (link to example), explaining the move from
master
tomain
, 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
master
dependency (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 --prune
-
Rename the local branch from
master
tomain
.git branch -m master main
-
Point the local
main
branch to the remotemain
one (assuming that the canonical remote is namedorigin
in your clone).git branch -u origin/main main
-
Adjust your local current HEAD, that still is pointing to the, now gone,
master
branch.git remote set-head origin -a
-
Verify 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