Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

community creator

How to rename a default branch in Git and GitHub

Aman Mittal

In this shot, we'll learn to rename a default branch in Git and GitHub. Below are the steps to do that. All of these commands execute inside a terminal window.

Start by moving the default branch locally using the -m flag:

git branch -m master main

Above, master is the old branch name and main is the new branch name.

Set the new branch as the local default on the remote. By default, Git doesn't allow a remote branch to be renamed.

Set the current local head branch to point to the new branch on GitHub:

git remote set-head origin main

Next, go to the GitHub repo. Open "Settings" -> "Branches." Under "Default Branch," click the "Edit" button to switch to the main branch:


Then, go back to the terminal window and run the following command to delete the previous default branch name:

git push origin --delete master

# output
- [deleted]         master


community creator

View all Courses

Keep Exploring