Last active
June 15, 2020 16:47
-
-
Save lpar/c74f661a17d52b942bfb8b1fd1496972 to your computer and use it in GitHub Desktop.
Change the name of your default Git branch to `trunk`.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh -e | |
# | |
# This is a terrible hack of a Github script to change the name of your | |
# default or main branch from 'master' to 'trunk', both in your local | |
# repo and on Github. I don't usually write shell scripts, so if someone | |
# wants to clean it up and make it robust, that'd be great. | |
# | |
# As to why you might want to rename your default branch... | |
# | |
# Consider that the entire metaphor of source control is that of a | |
# tree with branches. The main part of a tree that the branches split | |
# off from is the trunk. Trees have branches, masters do not, so calling | |
# the root of a set of branches "master" never made metaphorical sense, | |
# and "trunk" more clearly expresses the relationship. | |
# | |
# Consider also | |
# https://tools.ietf.org/id/draft-knodel-terminology-00.html | |
# | |
# You must be owner of the repo to change the default branch on Github. | |
# | |
# You need the Github 'hub' command line installed, | |
# see https://hub.github.com/ | |
# | |
# People with existing clones of the repo will need to do the following to | |
# fix up their repos: | |
# | |
# git checkout master | |
# git branch -m master trunk | |
# git fetch | |
# git branch --unset-upstream | |
# git branch -u origin/trunk | |
# git symbolic-ref refs/remotes/origin/HEAD refs/remotes/origin/trunk | |
# | |
# Named elephantoplasty because it's a cosmetic operation, and Monty | |
# Python. | |
# Set your Github user name and password here | |
export GITHUB_USER=myghid | |
export GITHUB_PASSWORD=12345 | |
git branch -m master trunk | |
git push -u origin trunk | |
hub api -t -XPATCH 'repos/{owner}/{repo}' -f default_branch="trunk" > /dev/null | |
git push origin --delete master |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks to @GaugeK for cleanup.
Note that this also works for Enterprise Github, if you
export GITHUB_HOST=github.example.com
or whatever your enterprise domain is. You may need to set up an access token to use instead of a password, if your Github Enterprise deployment uses SSO.