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 the git branch command the master branch was renamed to main successfully!
% git branch --move master main
fatal: a branch named 'main' already exists

This is not an AI-generated article but is demonstrated by a human on an M1 Mac running macOS Sonoma 14.0.
Please support independent contributors like Code2care by donating a coffee.
Buy me a coffee!

Comments & Discussion
Facing issues? Have questions? Post them here! We're happy to help!