CLI to rename a branch on GitHub repositories
You need to create a personal access token with the "repo" scope: https://github.com/settings/tokens/new?scopes=repo
Replace <ACCESS TOKEN>
below with the token you just created.
Rename branch for specific repository
npx rename-github-branch --token=<ACCESS TOKEN> --repo=gr2m/rename-github-branch
Rename branch for all repositories in an organization or account
npx rename-github-branch --token=<ACCESS TOKEN> --owner=gr2m
- Creates a new reference using the
sha
of the last commit ofcurrent_branch
(POST /repos/:owner/:repo/git/refs
) - Updates the default branch of the repository (
PATCH /repos/:owner/:repo
) - Updates branch protection to the new branch name if applicable (GraphQL mutation
updateBranchProtectionRule
) - Look for open pull requests and update the base branch if it’s
current_branch
(PATCH /repos/:owner/:repo/pulls/:number
) - Delete
current_branch
(DELETE /repos/:owner/:repo/git/refs/:ref
)
I think master
is a horrific term. git
& GitHub should follow the lead of
tech communities such as Django,
Drupal and
CouchDB and replace
master
with non-offensive term, such as latest
. This library is meant to
simplify the process of renaming branch names of GitHub repositories.