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 the 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

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!

Buy Code2care a Coffee!

Facing issues? Have Questions? Post them here! I am happy to answer!

Author Info:

Rakesh (He/Him) has over 14+ years of experience in Web and Application development. He is the author of insightful How-To articles for Code2care.

Follow him on: X

You can also reach out to him via e-mail: rakesh@code2care.org



















Copyright © Code2care 2024 | Privacy Policy | About Us | Contact Us | Sitemap