Skip to content

Instantly share code, notes, and snippets.

@benjamine
Last active December 9, 2021 22:46
Show Gist options
  • Save benjamine/5862852 to your computer and use it in GitHub Desktop.
Save benjamine/5862852 to your computer and use it in GitHub Desktop.
Delete your fork master branch, useful when using feature branches

When working with feature branches, the master branch on your fork becomes useless (you probably base your branches on upstream/master). As a result you fork's master gets outdated, and can lead to mistakes.

Deleting it is a good idea, but github needs a "default branch" to show on website, this script will create an orphan "_default" branch with just an explanatory README.md on it, and set that as default for github (you'll be asked your github password).

DISCLAIMER: This script will delete your master branch locally and remotely, be sure you don't need it anymore before running this!

git checkout -b _default
git rm -rf .
git clean -xdf
bash echo "Nothing to see here, just a placeholder branch" > README.md
bash echo "---" >> README.md
bash echo >> README.md
bash echo "Do you want one like this? [here](https://gist.github.com/benjamine/5862852)" >> README.md
git add README.md
git commit -m "initial commit"
git push origin _default
git config --global alias.set-github-default "!f() { curl -u $(git config --get remote.origin.url | cut -d : -f2 | cut -d / -f1) -d '{\"name\": \"'\"$(git config --get remote.origin.url | cut -d / -f2 | cut -d . -f1)\"'\", \"default_branch\":\"'\"$1\"'\"}' https://api.github.com/repos/$(git config --get remote.origin.url | cut -d : -f2 | cut -d . -f1); }; f"
git set-github-default _default
git branch -D master
git push origin --delete master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment