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
master
* 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

main
* 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!