Enhancing Skills

Renaming the Default Git Branch from master to main

As part of a move toward more inclusive language in software development, many Git platforms and tools have transitioned from using master as the default branch name to main. Renaming the primary branch in your Git repository is a straightforward process but requires a few steps to ensure everything continues to work smoothly, both locally and remotely. This guide will walk you through the process of renaming your master branch to main, updating your remote repository, and ensuring your workflow remains intact.


To rename the master branch to main, follow these steps:

1. Rename the Local Branch

First, rename the local master branch to main.

$ git branch -m master main

2. Push the Renamed Branch to Remote

Next, push the newly renamed main branch to the remote repository.

$ git push -u origin main

3. Update the Default Branch on the Remote Repository

On platforms like GitHub, GitLab, or Bitbucket, you need to update the default branch to main.

To change the default branch on GitHub, follow these steps:

  1. Navigate to Your Repository:
    • Go to the GitHub website and navigate to the repository for which you want to change the default branch.
  2. Go to Repository Settings:
    • Click on the “Settings” tab, which is usually located on the right side of the repository’s menu bar.
  3. Change the Default Branch:
    • Under the “Default branch” section, click the “Change default branch” button.
    • A dropdown menu will appear, allowing you to select a new default branch from the list of existing branches.
    • Choose the branch you want to set as the new default.
  4. Confirm the Change:
    • After selecting the new default branch, click “Update” to confirm the change.
  5. Review the Impact:
    • Review any implications this change might have, such as affecting open pull requests or the branch that is checked out by default for clones.

4. Delete the Old master Branch on Remote

If you no longer need the master branch on the remote, you can delete it.

$ git push origin --delete master

5. Update Local Branch Tracking

Finally, you may need to update any local clones of the repository to track the new main branch.

$ git fetch origin
$ git branch -u origin/main main

This will ensure that your local main branch is tracking the correct remote branch.


Renaming the primary branch from master to main involves a few critical steps: renaming the branch locally, pushing the changes to the remote repository, updating the default branch settings on your remote platform, and optionally deleting the old master branch. By following these steps, you can align with modern best practices while maintaining the integrity of your repository and workflow. This change helps ensure that your repository reflects a more inclusive environment, without disrupting your development process.


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.