Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does the -M mean in git branch -M main?

Tags:

git

GitHub says to enter git branch -M main as a step for creating a new repository on the command line. What does the -M mean?

like image 961
nCardot Avatar asked Sep 01 '25 10:09

nCardot


2 Answers

-M is a flag (shortcut) for --move --force per the docs page on git branch. It forcefully renames the branch from master (the default branch name for repositories created using the command line is master, while those created in GitHub [starting in Oct. 2020] have a default name of main) to main.

It allows the renaming of the branch even if the new branch name already exists.

like image 137
nCardot Avatar answered Sep 02 '25 23:09

nCardot


git branch -M main

-M automatically renames the master branch to main.

like image 35
Duru Cynthia Udoka Avatar answered Sep 03 '25 00:09

Duru Cynthia Udoka