To change the default branch in a GitHub repository, you need admin permissions and at least two branches in the repo.
docs.github
Using the web interface (github.com)
- Open the repository (for example:
github.com/username/repo-name). - Go to the Settings tab under the repository name (if you don’t see it, select it from the right-hand menu).
- In the left sidebar, find the Default branch section.
- Click the button next to the current default branch name, and from the dropdown list, select the branch you want to set as the new default.
- Click Update.
- Read the warning message and confirm by clicking I understand, update the default branch.
From now on, new pull requests and commits will use this selected branch as the default base branch.
docs.github
Using GitHub CLI (optional)
If you use the gh CLI in your terminal and are inside the repository’s directory, you can run:
gh repo edit --default-branch main
to set the default branch to main (the branch must already exist).
stackoverflow
If you’d like, tell me which method you’re using (web only or CLI as well), and I can walk you through it step by step.
Would you like me to make this version more formal (for documentation) or conversational (for a guide or tutorial)?