ghdefaultbranch
Rename your Github branch from its current default (likely "master"), to a new default (likely "main")
Can be run against a single repo, or all repos the user owns
After the default branch has been renamed, contributors to the repo will see
Which asks the user to run the following on their local copy (assuming an old name of master, and a new name of main)
git branch -m master main
git fetch origin
git branch -u origin/main main
git remote set-head origin -a
Usage
By default without arguments, this program will print all repos the token has access to.
Optional ENV variables
- ghdefaultbranchToken: Should be set to a Github API Token with access to the repos you are checking
- Set permissions for token to repo - full control of private repositories, enable SSO if your repos require it
- If not set, program will prompt user to enter a token at run time.
Example configuration in ~/.bashrc
export ghdefaultbranchToken=e0e9eac4e84446df6f3db180d07bfb222e91234
Running the progam
Usage of ghdefaultbranch:
-askToken
Bool: Force user to enter token instead of trying the env variable ghdefaultbranchToken
-defaultBranch string
Name of the desired defaultBranch, used with renameAll and repository flags (default "main")
-renameAll
Bool: rename default branch in all repos or not
-repository string
Repository to rename branch on, example: Jmainguy/timesheets, not used if renameAll flag is specified
Examples
Set default branch for k8sCapCity to juneteenth
[jmainguy@jmainguy ghdefaultbranch]$ ghdefaultbranch -repository Jmainguy/k8sCapCity -defaultBranch "juneteenth"
Set default branch for k8sCapCity to main
[jmainguy@jmainguy ghdefaultbranch]$ ghdefaultbranch -repository Jmainguy/k8sCapCity
Set default branch to main for all repos token has access to
[jmainguy@jmainguy ghdefaultbranch]$ ghdefaultbranch -renameAll
List all repos token has access to
[jmainguy@jmainguy ghdefaultbranch]$ ghdefaultbranch
Sample output
There is no output when changing default branch, unless an error is encountered.
This is the example output if no arguments passed (list all repos)
FullName: Jmainguy/relevy-web, DefaultBranch: main, HTMLURL: https://github.com/Jmainguy/relevy-web
FullName: Jmainguy/repeatafterme, DefaultBranch: main, HTMLURL: https://github.com/Jmainguy/repeatafterme
FullName: Jmainguy/rshell, DefaultBranch: main, HTMLURL: https://github.com/Jmainguy/rshell
Linux / macOS homebrew install
brew install jmainguy/tap/ghdefaultbranch
Releases
We currently build releases for RPM, DEB, macOS, and Windows.
Grab Release from The Releases Page
Build it yourself
export GO111MODULE=on
go build