Skip to content

Instantly share code, notes, and snippets.

@ecomba
Created July 1, 2020 10:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ecomba/d6b442e2855c9f74bf612ed50e7cc982 to your computer and use it in GitHub Desktop.
Save ecomba/d6b442e2855c9f74bf612ed50e7cc982 to your computer and use it in GitHub Desktop.
Little tool that helps you moving away from 'master' as your default branch (and deletes master in the process)
#!/bin/bash
function pause(){
read -p "$*"
}
echo "This script will help you rename your default branch (master) to"
echo "a name of your choosing."
echo ""
echo "Let's rebase your local repository with your origin first"
echo ""
git fetch origin
git rebase origin/master
echo ""
read -p "What do you want to call your new default branch? " branch_name
echo ""
echo "Nice one! Let's create $branch_name"
git branch -m master $branch_name
echo ""
echo "And push it to 'origin'"
echo ""
git push -u origin $branch_name
echo ""
echo "Let's update the tracking branch to $branch_name"
echo ""
git branch -u origin/main $branch_name
echo ""
echo "We are almost done now."
echo ""
echo "But this time you have to change the default branch in github from"
echo "'master' to '$branch_name'."
echo "You can do this by pointing your browser to your repository"
echo "and navigate to 'Settings->Branches'"
echo ""
echo "Choose your new branch ($branch_name) as your default branch."
echo ""
echo "Once you've done this we can continue."
echo "I'll wait till you do that."
echo ""
pause "Once you are done press the [Enter] key to continue..."
echo ""
pause "Have you changed your default branch to $branch_name? If so press [Enter]"
echo "Sorry for asking again, it's just important for the next step to work"
echo ""
echo "Time to delete the 'master' branch for good!"
echo ""
git push origin --delete master
echo ""
echo "We are done!"
echo ""
echo "Your default branch is now $branch_name, well done!"
echo ""
echo "This wasn't so hard, was it? A little step can help a lot!"
echo ""
echo "Thank you so much for making this happen in your repository!"
echo ""
echo "Have a great day!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment