When initializing a project with Git for local management, a master
branch is created. Since GitHub often promotes the use of "main" as the branch name, let's explore how to rename the branch.
git
CommandsWe will change the branch name from "master" to "main."
Initialize Git.
git init
Rename the branch.
git branch -m master main
git clone repository-url
cd repository
git branch -m master main
git push -u origin main
git push origin --delete master
On GitHub, you can rename the branch directly on the web without going through the above steps.
Rename branch
.To change the default branch name created during Git initialization to "main," use the following command:
git config --global init.defaultBranch main