Posts Learn Components new Snippets new Categories Tags About Device Beast sponsor

How to Rename the master branch to main in Git

Learn how to rename the master branch of your newly created repository to main.

Created on Jun 27, 2021


So you might just init git repository locally and the branch by default is set to "master". Since many of the git online repositories make use of "main" as the default one now, you'll have to rename it.

The command to change the branch name is like below, use "-m" flag to modify the branch name.
git branch -m master main

Now the branch name will be called "main" and you can push it to the online repository.
git push --set-upstream origin main

Snippets by

PostSrc poster


Full stack developer mainly focusing on the front end side of the web. The main author of PostSrc and loves writing tutorial and guides online.

Load comments for How to Rename the master branch to main in Git


PostSrc Code Components

Collection of Tailwind CSS components for everyone to use. Browse all of the components that are right for your project.

View Components

Other Code Snippets