Git Rename master branch make to main using Command

To rename a git branch from its name master to main make use of the git branch command with -m or --move option.

Let us see few examples:

% git branch
* ticket-123

As you can see, I have two branches currently for my repo and one of them is master which I want to rename as main.

% git branch --move master main
% git branch

* ticket-123

As you can see after using the move option along with git branch command the master branch was renamed to main successfully!

Note: If the main branch already exists you will get an error!

% git branch --move master main
fatal: a branch named 'main' already exists
Git - Rename master Branch name to main

Have Questions? Post them here!

Topics Coverage:

🎉 We are celebrating the 10th years of Code2care! Thank you for all your support!

We strongly support Gender Equality & Diversity.

Follow Us: GitHub | Facebook | Twitter | Instagram