On this article, I'll show how to update your default branch from "master" to "main".
Why do this?
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.
Set git init to "main"
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
Rename Branch
Let's rename your current "master" to "main" branch with the following code:
$ git branch -m master main
tl;dr
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
You'll see something like that:
Github: Settings
- Go to your repository at Github and access the
Settings
tabhttps://github.com/<username>/<repository>/settings
- Choose
Branches
on the sidebar - Update from
master
tomain
like 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
main
and deleted themaster
branch.
Wrapping Up
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
Top comments (0)