How to Change Default Branch in GitHub

When working with GitHub repositories, the default branch acts as the main line of development — it’s the branch where pull requests are merged and the one most contributors work with. Traditionally, this branch was named master, but now most repositories use main by default.

If you want to change your default branch in GitHub — whether to rename master to main, switch to another development branch, or manage workflow better — this guide will walk you through how to do it safely and correctly.

What Is the Default Branch in GitHub?

The default branch is the one GitHub automatically checks out when you clone a repository. It’s also used as the base for:

  • Pull requests
  • Merge operations
  • Deployments and automated workflows

For example, when you run:

git clone https://github.com/username/repository.git

the branch that gets cloned by default is the default branch.

By changing it, you can direct your development flow to another branch, such as dev, staging, or production.

When Should You Change the Default Branch?

You might need to change the default branch in scenarios like:

  • Migrating from mastermain for inclusive naming conventions.
  • Switching from a production branch to a development branch.
  • Managing multiple environments (e.g., main for release, dev for testing).
  • Standardizing branches across teams.

Step 1: Create or Verify the New Branch

Before changing the default branch, ensure the branch you want to set as default already exists.

  1. Go to your GitHub repository.
  2. Click the Branch dropdown near the top-left.
  3. Type your new branch name and click Create branch (if it doesn’t already exist).
  4. Verify that it appears in the branch list.

Pro Tip: If your desired branch already exists (e.g., main or dev), you can skip this step.

Step 2: Change the Default Branch from GitHub Website

Now that your new branch is ready, let’s make it the default branch in your repository settings.

  1. Navigate to your repository on GitHub.
  2. Click the ⚙️ Settings tab at the top.
  3. On the left sidebar, select Branches.
  4. Under the Default branch section, click the Edit button.
  5. Choose your new branch (e.g., main or dev) from the dropdown list.
  6. Click Update.

A prompt will appear asking you to confirm the change — review and confirm.

Note: GitHub automatically updates open pull requests and future merges to point to the new default branch.

Step 3: Delete the Old Default Branch (Optional)

If you no longer need the old default branch (for instance, if you renamed master to main), you can safely delete it.

  1. Go to your repository’s Branches page.
  2. Find the old branch (e.g., master).
  3. Click the trash bin icon next to it.
  4. Confirm deletion.

Caution: Make sure the branch has no unmerged commits before deleting it.

Step 4: Update Local Repositories

If you or your team have already cloned the repository, you’ll need to update your local Git configuration to reflect the new default branch.

  1. Open Command Prompt, Git Bash, or VS Code Terminal.
  2. Navigate to your repository: cd path/to/your/repository
  3. Fetch all branches: git fetch origin
  4. Switch to the new default branch: git checkout main
  5. Set the upstream branch: git branch -u origin/main
  6. Delete the old local branch (optional): git branch -d master

Tip: Replace main with your new branch name if different.

Step 5: Rename Local Branch (If Needed)

If you renamed your remote branch (e.g., mastermain), update your local branch name too.

  1. Run: git branch -m master main
  2. Push the renamed branch to GitHub: git push -u origin main
  3. Delete the old remote branch: git push origin --delete master

Pro Tip: This keeps your local and remote branches consistent and avoids confusion later.

Step 6: Verify the Change

Finally, confirm that the new branch is now set as default.

  1. Go back to your repository on GitHub.
  2. The branch dropdown (top-left) should show your new branch.
  3. Check pull requests — they should now target the new branch by default.

Wrapping Up

Changing your default branch in GitHub is simple, but it’s a critical step in maintaining a clean and organized workflow. Whether you’re switching from master to main, moving to a dev branch, or aligning your workflow with new standards, the process ensures your repository stays consistent across all collaborators.

After updating the default branch, remember to update local repos and notify your team so everyone works from the correct branch. With these steps, your GitHub repository will stay clean, efficient, and ready for smooth collaboration!

Posted by Arpita

With a background in Computer Science, she is passionate about sharing practical programming tips and tech know-how. From writing clean code to solving everyday tech problems, she breaks down complex topics into approachable guides that help others learn and grow.