{"id":13426010,"url":"https://github.com/mheap/github-default-branch","last_synced_at":"2025-09-08T18:31:06.393Z","repository":{"id":36960633,"uuid":"272283041","full_name":"mheap/github-default-branch","owner":"mheap","description":"Rename your default branch on GitHub","archived":false,"fork":false,"pushed_at":"2024-06-17T21:13:56.000Z","size":450,"stargazers_count":133,"open_issues_count":23,"forks_count":10,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-12-21T17:08:30.724Z","etag":null,"topics":["branch","cli","github","main","master","rename"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mheap.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-06-14T21:03:20.000Z","updated_at":"2024-10-05T07:00:35.000Z","dependencies_parsed_at":"2024-05-01T09:26:30.460Z","dependency_job_id":"2941d729-104f-413b-bb97-82f84ad094b6","html_url":"https://github.com/mheap/github-default-branch","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mheap%2Fgithub-default-branch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mheap%2Fgithub-default-branch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mheap%2Fgithub-default-branch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mheap%2Fgithub-default-branch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mheap","download_url":"https://codeload.github.com/mheap/github-default-branch/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":232333558,"owners_count":18507054,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["branch","cli","github","main","master","rename"],"created_at":"2024-07-31T00:01:24.170Z","updated_at":"2025-01-03T12:11:34.610Z","avatar_url":"https://github.com/mheap.png","language":"JavaScript","readme":"# GitHub Default Branch\n\nRename your default branch on GitHub easily. By default it renames `master` to `main`, but is configurable using the `--new` and `--old` flags.\n\nIf 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. See [Usage](#usage) for more examples.\n\nFor each repo, this tool will:\n\n- Create a new branch at the same commit SHA as the old one\n- Update all open pull requests to point at the new branch\n- Update the default branch for the repo\n- Delete the old branch\n- Update [known URL patterns](https://github.com/mheap/github-default-branch/tree/main/replacements) in source files\n- Update any branch protections for `$old` to `$new`. (This does **not** work with patterns, it has to be an exact match)\n\n## Installation\n\n```shell\nnpm install -g github-default-branch\n```\n\n## Development\n\n```shell\ngit clone https://github.com/mheap/github-default-branch.git\ncd github-default-branch\nnpm ci\n```\n\n## Authentication\n\n[Create a personal access token](https://github.com/settings/tokens/new?scopes=repo\u0026description=github-default-branch) with the `repo` scope. This is the value for `\u003ctoken\u003e` in the examples.\n\n\u003e If you don't want your token to be stored in your shell history, you can set `GITHUB_TOKEN` in the environment and that will be read instead\n\n## Usage\n\n```\n# Rename master to main\ngithub-default-branch --pat \u003ctoken\u003e --repo user/repo\n\n# Rename dev to develop\ngithub-default-branch --pat \u003ctoken\u003e --repo user/repo --old dev --new develop\n\n# Rename all repos owned by an org\ngithub-default-branch --pat \u003ctoken\u003e --org my-org-name\n\n# Rename all repos owned by a user\ngithub-default-branch --pat \u003ctoken\u003e --user my-user\n\n# Rename all repos owned by a team\ngithub-default-branch --pat \u003ctoken\u003e --org my-org-name --team my-team-slug\n```\n\nSet `DEBUG=\"ghdb*\"` as an environment variable to see debug information\n\n## Options\n\n| Flag          | Description                                                                                                  | Default |\n| ------------- | ------------------------------------------------------------------------------------------------------------ | ------- |\n| --pat \u003ctoken\u003e | GitHub API Token                                                                                             | N/A     |\n| --old         | The name of the branch to rename                                                                             | master  |\n| --new         | The new branch name                                                                                          | main    |\n| --repo \u003cname\u003e | The repo to update (format: user/repo)                                                                       | N/A     |\n| --user \u003cname\u003e | Update all repos owned by the provided user (example: my-user)                                               | N/A     |\n| --org \u003cname\u003e  | Update all repos in the provided org (example: my-org-name)                                                  | N/A     |\n| --team \u003cname\u003e | Update all repos in the provided team (example: my-team-name), only usable in combination with org parameter | N/A     |\n| --dry-run     | Output log messages only. Do not make any changes                                                            | false   |\n| --skip-forks  | Skips forked repositories                                                                                    | false   |\n| --confirm     | Run without prompting for confirmation                                                                       | false   |\n\n## Skipping transforms\n\nYou 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`.\n\n## Available transforms\n\n| Transform               | Description                                           |\n| ----------------------- | ----------------------------------------------------- |\n| update-default-branch   | Set the default branch of the repo to `$new`          |\n| retarget-pull-requests  | Change the base for any open pull requests            |\n| retarget-draft-releases | Change the `target_commitish` for any draft releases  |\n| branch-protection       | Update any branch protection rules to point at `$new` |\n| delete-old-branch       | Delete the `$old` branch                              |\n| github-pages            | Update GitHub Pages configuration                     |\n\nPending transforms:\n\n- Copy branch protections instead of updating if `--skip-delete-old-branch` is used ([#26](https://github.com/mheap/github-default-branch/issues/26))\n- Retarget draft releases ([#30](https://github.com/mheap/github-default-branch/issues/30))\n\n## Replacements\n\nPart of this script checks for the existence of files and updates their contents. Replacements are the mechanism for these updates.\n\n### How it Works\n\nEach .js file in the `replacements` 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.\n\nIf there is nothing to replace, then the script moves on to the next replacement.\n\n### How to Add a Replacement\n\nAdd a file to `replacements` with a .js extension\n\nLike this:\n\n```javascript\nmodule.exports = function ({\n  owner, // string - repo owner\n  repo, // string - repo name\n  old, // string - old branch name\n  target, // string - new branch name\n  octokit, // Octokit - oktokit instance\n  verbose, // boolean - verbose flag\n  isDryRun, // boolean - dry run flag\n}) {\n  // code goes here\n  return {\n    path: \"\u003cpath to file in repo\u003e\",\n    replacements: [\n      {\n        from: \"\u003cfrom string\u003e\",\n        to: \"\u003cto string\u003e\",\n      },\n      {\n        from: \"\u003cfrom string\u003e\",\n        to: \"\u003cto string\u003e\",\n      },\n    ],\n  };\n};\n```\n\nThe file with the path in your repo will have any line matching `from` be swapped out with `to`\n","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmheap%2Fgithub-default-branch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmheap%2Fgithub-default-branch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmheap%2Fgithub-default-branch/lists"}