Branches are just labels for commits (including their history). Also, all branches are basically the same, but we decided ("arbitrarily") that one is the one we do our main work on (this branch could also be named dev
, default
or something else).
You have several ways to achieve to have a main
branch. One is:
- Create a new local branch
main
that should be your new main branch from now on (you might want to fetch the remote repository before to get the latest changes)
- Push that branch to GitHub and select "Set upstream/track remote branch" (you might need to push with "force" to hard overwrite the remote branch on GitHub).
- On GitHub go to the project settings -> Branches and select
main
as your new default branch (can also be done using git remote set-head origin -a
on the CLI.
- Delete your local
master
branch and the remote master
branch on GitHub. (Basically you can also decide to keep your old master branch for some time so that the transition is easier for other people using your repository. Then, however, you need to merge the change of your main
branch to the old master
regularly.)
There might be easier ways, but based on your question it is not clear what your current state in the repository currently is.
An alternative could be to switch to a new temporary branch (name doesn't matter, should not be main
), rename your current local master
branch to main
using the Reference Browser, and then proceeding with step 2 (make sure the remote branch is also named main
). Then, switch to the new main
branch and finally delete the temporary branch.
If you want to have main
as the default for new repositories, you need to set the Git default using git config --global init.defaultBranch main
on the CLI (this does not change any exitsing repositories).