How to Change Default Branch in GitHub (Step-by-Step Guide)


XINSTALL BY CLICKING THE DOWNLOAD FILE
A message from our partner

For fixing Windows errors, we recommend Fortect:

Fortect will identify and deploy the correct fix for your Windows errors. Follow the 3 easy steps to get rid of Windows errors:

  • Download Fortect and install it on your PC
  • Launch the tool and Start scanning your PC for Windows errors
  • Right-click on Start Repair to deploy the right fix for each error encountered during the scan
Download Now Fortect has been downloaded by 0 readers this month, rated 4.6 on TrustPilot

If you want to learn how to change default branch in GitHub, this guide will help you. It will teach you how to switch the default branch using both the GitHub website and Git commands on your computer.

How to Change Default Branch on GitHub?

1. Change Default Branch on GitHub Website

Follow these steps directly from your repository settings:

  1. Open your repository on GitHub.
  2. Click Settings from the top menu.
  3. Go to Branches in the left sidebar.
  4. Under Default branch, click the edit button.
  5. Select the new branch from the dropdown.
  6. Confirm by clicking Update.

Your repository now uses the new branch as the default.

For related tasks, you may also want to learn how to create a folder in GitHub.

2. Change Default Branch with Git Locally

If you prefer working with the terminal:

  1. Open your terminal and navigate to your repo folder.
  2. Rename the branch (example: master to main):
git branch -m master main
  1. Push the renamed branch to GitHub:
git push -u origin main
  1. Delete the old branch from the remote:
git push origin --delete master

Afterward, update the default branch in the GitHub settings as shown above.

If you run into merge problems while switching branches, see this guide on how to resolve conflicts in GitHub.

Why Change the Default Branch?

The default branch is where all new pull requests and commits point. You may want to switch from master to main, or use another branch as the main development line.

FAQs

How do I rename the master branch to main in GitHub?

You can rename it locally, push the change to GitHub, and then update the default branch in the repository settings.

Does changing the default branch delete the old one?

No. The old branch still exists until you manually delete it.

Will contributors be affected when I change the default branch?

Yes. Pull requests will redirect to the new branch, so notify your team before making the switch.

Can I switch back to the old branch as default?

Yes. You can change the default branch again in the settings at any time.

Conclusion

Learning how to change default branch in GitHub is simple and ensures your project stays organized. You can update it in a few clicks on the GitHub website or by using Git commands locally. For more, check out how to approve a pull request in GitHub.

More about the topics: Github

Readers help support Windows Report. We may get a commission if you buy through our links. Tooltip Icon

Read our disclosure page to find out how can you help Windows Report sustain the editorial team. Read more

User forum

0 messages