- Notifications
You must be signed in to change notification settings - Fork10
Rename your default branch on GitHub
License
mheap/github-default-branch
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
Rename your default branch on GitHub easily. By default it renamesmaster tomain, but is configurable using the--new and--old flags.
If provided with an--org,--user or (--org and--team) arguments, it will run on all repositories owned by that org, user or team. Alternatively, you can provide a--repo argument to edit a single repo. SeeUsage for more examples.
For each repo, this tool will:
- Create a new branch at the same commit SHA as the old one
- Update all open pull requests to point at the new branch
- Update the default branch for the repo
- Delete the old branch
- Updateknown URL patterns in source files
- Update any branch protections for
$oldto$new. (This doesnot work with patterns, it has to be an exact match)
npm install -g github-default-branch
git clone https://github.com/mheap/github-default-branch.gitcd github-default-branchnpm ciCreate a personal access token with therepo scope. This is the value for<token> in the examples.
If you don't want your token to be stored in your shell history, you can set
GITHUB_TOKENin the environment and that will be read instead
# Rename master to maingithub-default-branch --pat <token> --repo user/repo# Rename dev to developgithub-default-branch --pat <token> --repo user/repo --old dev --new develop# Rename all repos owned by an orggithub-default-branch --pat <token> --org my-org-name# Rename all repos owned by a usergithub-default-branch --pat <token> --user my-user# Rename all repos owned by a teamgithub-default-branch --pat <token> --org my-org-name --team my-team-slugSetDEBUG="ghdb*" as an environment variable to see debug information
| Flag | Description | Default |
|---|---|---|
| --pat | GitHub API Token | N/A |
| --old | The name of the branch to rename | master |
| --new | The new branch name | main |
| --repo | The repo to update (format: user/repo) | N/A |
| --user | Update all repos owned by the provided user (example: my-user) | N/A |
| --org | Update all repos in the provided org (example: my-org-name) | N/A |
| --team | Update all repos in the provided team (example: my-team-name), only usable in combination with org parameter | N/A |
| --dry-run | Output log messages only. Do not make any changes | false |
| --skip-forks | Skips forked repositories | false |
| --confirm | Run without prompting for confirmation | false |
You might want to skip any of the available transforms (such as deleting the old branch). You can add--skip-[transform-name] to disable the transform e.g.--skip-delete-old-branch.
| Transform | Description |
|---|---|
| update-default-branch | Set the default branch of the repo to$new |
| retarget-pull-requests | Change the base for any open pull requests |
| retarget-draft-releases | Change thetarget_commitish for any draft releases |
| branch-protection | Update any branch protection rules to point at$new |
| delete-old-branch | Delete the$old branch |
| github-pages | Update GitHub Pages configuration |
Pending transforms:
- Copy branch protections instead of updating if
--skip-delete-old-branchis used (#26) - Retarget draft releases (#30)
Part of this script checks for the existence of files and updates their contents. Replacements are the mechanism for these updates.
Each .js file in thereplacements folder is given a chance to run during the content updating step of the script. Each file in replacements is expected to export a function, that function receives all of the options that are available to the outmost script.
If there is nothing to replace, then the script moves on to the next replacement.
Add a file toreplacements with a .js extension
Like this:
module.exports=function({ owner,// string - repo owner repo,// string - repo name old,// string - old branch name target,// string - new branch name octokit,// Octokit - oktokit instance verbose,// boolean - verbose flag isDryRun,// boolean - dry run flag}){// code goes herereturn{path:"<path to file in repo>",replacements:[{from:"<from string>",to:"<to string>",},{from:"<from string>",to:"<to string>",},],};};
The file with the path in your repo will have any line matchingfrom be swapped out withto
About
Rename your default branch on GitHub
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors10
Uh oh!
There was an error while loading.Please reload this page.