On this article, I'll show how to update your default branch from "master" to "main".
I really recommend you look for more about and take your own decisions about, in this article I'll focus only on changing the default branch and don't go deeper into the motivation about it.
The new repositories created on Github will be set to "main" as default, it started October 01st, read more about it.
To set as default to initialize repositories with
main you can do the following:
$ git config --global init.defaultBranch main
Or add to your
.gitconfig like this
Let's rename your current "master" to "main" branch with the following code:
$ git branch -m master main
Rename a branch (must not have it checked out to do this):
git branch -m old_branch_name new_branch_name
After rename, push to the remote origin:
$ git push origin main
- Go to your repository at Github and access the
Brancheson the sidebar
- Update from
mainlike the following image:
- It will show an alert modal, you just need to accept then:
- Now, if you go to the root link at your repository you'll see the current default branch:
- Notice has 2 branches in this case, one is the
master, you can delete with the following code:
$ git push --delete origin master
- Tadah! Now you have just the
mainand deleted the
I updated some of my personal repositories and I think it can be helpful for some people.
If it helped you in some way, feel free to comment below or share the article.
Enjoy Programming! :D