Skip to content

Instantly share code, notes, and snippets.

@MiguelCamilo
Last active July 31, 2023 16:33
Show Gist options
  • Save MiguelCamilo/84ee1384ca399335affe7d386cfe14b2 to your computer and use it in GitHub Desktop.
Save MiguelCamilo/84ee1384ca399335affe7d386cfe14b2 to your computer and use it in GitHub Desktop.
ALL STEPS ON HOW TO CHANGE MAIN BRANCH NAME AND MAKE YOUR CUSTOM BRANCH THE DEFAULT BRANCH

ALL STEPS ON HOW TO CHANGE MAIN BRANCH NAME AND MAKE YOUR CUSTOM BRANCH THE DEFAULT BRANCH

Changing the default branch in GITHUB SETTING

Here are a few ways to rename the main branch in Git:

1. Rename the local branch:

git branch -m main new-main-branch

This renames your local main branch to new-main-branch.

2. Push the renamed branch to remote:

git push origin new-main-branch --set-upstream

This pushes the renamed branch to the remote origin and sets it to track the new name.

3. Delete the old remote branch:

git push origin --delete main

Remove the old main branch name from the remote.

4. Change the default branch on remote:

On GitHub or your Git host, change the default branch to point to the new name.

5. Update local references:

git remote set-head origin -a

This updates your local repo to pull from the new default branch.

6. Clean up old references:

git remote prune origin 

Prunes stale remote tracking branches.

That's the basic flow - rename locally, push new branch as default, delete old branch name, and update remote references. Just make sure any collaborators are aware of the change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment