Github offers a migration option, so it's trivial. But even with any other service like gitlab that doesn't have something like that (yet), as long as you're doing the right steps it's relatively straight-forward, at least from a technical point of view.
Either way, unless your project is quite small, the biggest hassle will surely be getting all your contributors to apply fixes to work-in-progress correctly.
What you need to do
Github
On your project page, navigate to settings, and in the section "Default branch", press the edit button and change it from master to main.
Gitlab, aka migrating manually
I'm assuming that your remote/upstream is called origin - if it's called something different, replace origin with that name in all commands accordingly.
- Rename the most recent
master to main, and push it upstream:
git fetch origin
git branch --move master main
git push --set-upstream origin main
Tell your upstream that main is the new default:
- Navigate to
settings/repository, section "Default branch", select main and press "Save Changes". Then, on the same page, go the the section "Protected branches", and protect main and unprotect master, and press "Save Changes".
Delete master on upstream - not strictly necessary, but does reduce confusion:
git push origin --delete master
- Migrate open merge/pull requests that wanted to be pushed into
master to be pushed into main instead:
- On an open merge request, press "edit". On the top, it should say "From <branch_name> into
master". Change the drop-down from master to main.
What your collaborators/colleagues need to do
git fetch origin --prune && git branch -m master main && git branch --set-upstream-to=origin/main main
As far as I know, that's it - the &&s are a good idea to protect you in case something doesn't add up.
Please leave a comment if you ran into issues following this advice. git fuckups are hellish to untangle, so the least we can do is to try and not reinvent the wheel any more than we need to.