Skip to content

Instantly share code, notes, and snippets.

@KumarManoj-S
Last active November 3, 2020 03:50
Show Gist options
  • Save KumarManoj-S/503593948dc6af13102b318a82561393 to your computer and use it in GitHub Desktop.
Save KumarManoj-S/503593948dc6af13102b318a82561393 to your computer and use it in GitHub Desktop.
Renaming the default branch (master) to a different name.
# consider the default branch is master and we want to rename it to prod
# Steps to rename the default branch master,
# 1. Branch off from master to a new branch called prod.
git checkout -b prod
# 2. set up upstream and push the renamed branch
git push -u origin prod
# 3. Update the default branch as prod in bitbucket, Github, gitlab, etc.
# Incase of bitbucket,
# go to [your repository] >> Repository Settings >> General >> Repository details >> Advanced >> set Main branch to prod
# 4. Delete the master branch from your local
git branch -d master
# 5. If the master is a restricted branch, then either disable the permission or edit the permission to make the prod as restricted.
# 6. Now delete the remote master branch
git push origin --delete master
# 7. Update the upstream's remote HEAD
git remote set-head origin -a
# To accommodate the changes for the other team members, do the following steps,
# 1. Fetch all the new branches
git fetch --all
# 2. Update the upstream's remote HEAD
git remote set-head origin -a
# 3. Set upstream to prod
git branch --set-upstream-to origin/prod
# 4. Rename master to prod
git branch -m master prod
# Thanks, Manoj Kumar
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment