• Stars
    star
    134
  • Rank 269,453 (Top 6 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 4 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Rename your default branch on GitHub

GitHub Default Branch

Rename your default branch on GitHub easily. By default it renames master to main, 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. See Usage 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
  • Update known URL patterns in source files
  • Update any branch protections for $old to $new. (This does not work with patterns, it has to be an exact match)

Installation

npm install -g github-default-branch

Development

git clone https://github.com/mheap/github-default-branch.git
cd github-default-branch
npm ci

Authentication

Create a personal access token with the repo 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_TOKEN in the environment and that will be read instead

Usage

# Rename master to main
github-default-branch --pat <token> --repo user/repo

# Rename dev to develop
github-default-branch --pat <token> --repo user/repo --old dev --new develop

# Rename all repos owned by an org
github-default-branch --pat <token> --org my-org-name

# Rename all repos owned by a user
github-default-branch --pat <token> --user my-user

# Rename all repos owned by a team
github-default-branch --pat <token> --org my-org-name --team my-team-slug

Set DEBUG="ghdb*" as an environment variable to see debug information

Options

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

Skipping transforms

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.

Available transforms

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 the target_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-branch is used (#26)
  • Retarget draft releases (#30)

Replacements

Part of this script checks for the existence of files and updates their contents. Replacements are the mechanism for these updates.

How it Works

Each .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.

If there is nothing to replace, then the script moves on to the next replacement.

How to Add a Replacement

Add a file to replacements 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 here
  return {
    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 matching from be swapped out with to

More Repositories

1

trello-cli

Command line client for Trello
TypeScript
294
star
2

Silex-Extensions

Collection of Extensions for Silex
PHP
116
star
3

github-action-required-labels

Fail the build if/unless a certain combination of labels are applied to a pull request
JavaScript
91
star
4

phpunit-github-actions-printer

PHP
70
star
5

Silex-Assetic

PHP
68
star
6

pin-github-action

Pin your GitHub actions to a specific hash
JavaScript
67
star
7

socketio-chat-example

JavaScript
36
star
8

github-update-secret

Update a GitHub Secret in all your repos at the same time
JavaScript
35
star
9

phpunit-matcher-action

Add annotations to your PHPUnit tests when running under Github Actions
JavaScript
32
star
10

octokit-commit-multiple-files

Octokit plugin to create/update multiple files at once
JavaScript
29
star
11

Silex-Memcache

PHP
24
star
12

require-checklist-action

JavaScript
23
star
13

github-social-image

JavaScript
19
star
14

automatic-approve-action

Automatically approve workflow runs for new contributors
JavaScript
13
star
15

markdown-to-jira

Create Jira tickets from a plain text format
JavaScript
12
star
16

Instapaper-XAuth-PHP

Small helper class for making requests to the Instapaper API
PHP
11
star
17

pocket-auth

JavaScript
10
star
18

github-action-pr-heroku-review-app

JavaScript
9
star
19

dotfiles-v1

Vim Script
9
star
20

pocket-auth-cli

JavaScript
9
star
21

github-action-hold-your-horses

JavaScript
8
star
22

problem-matcher

Problem Matcher implementation in node.js
JavaScript
8
star
23

iTunes-Library-Parser

Class to parse iTunes Library XML Files
PHP
8
star
24

submodule-sync-action

JavaScript
7
star
25

pocket-tagger

JavaScript
7
star
26

Silex-Markdown

PHP
7
star
27

Silex-Gravatar

PHP
6
star
28

regex-rules

JavaScript
5
star
29

github-action-issue-to-jira

JavaScript
5
star
30

ansible-module-mas

Python
5
star
31

Gnosis

Knowledge base app based on Markdown files
PHP
5
star
32

pocket-tagger-cli

JavaScript
5
star
33

Silex-Assetic-Demo

PHP
5
star
34

phpnw-ansible-playbooks

Ruby
5
star
35

Silex-Mongo

PHP
5
star
36

github-new

JavaScript
4
star
37

Silex-Embedly

PHP
4
star
38

hold-your-horses

Hold your horses! is a Github status check that will leave a pending status check open for a certain period of time, leaving plenty of time for code reviews.
JavaScript
4
star
39

github-action-issue-management

Automatically manage your issue labels
JavaScript
4
star
40

passport-offline

JavaScript
3
star
41

markdown-meta-action

JavaScript
3
star
42

action-router

Handle multiple GitHub Actions events in a single action
JavaScript
3
star
43

Behat-Selenium2-Webdriver-MinkExtension-Example

PHP
3
star
44

github-show-actions

Show all GitHub Actions used by a user/org
JavaScript
3
star
45

frontmatter-json-schema-action

Validate YAML frontmatter against a JSON schema
JavaScript
3
star
46

action-guard

JavaScript
3
star
47

macos-dotfiles

Ruby
3
star
48

jenkins-global-library-demo

Groovy
3
star
49

mastering-express

Reference code for Mastering Express Web Application Development- https://www.packtpub.com/web-development/mastering-express-web-application-development-video
JavaScript
3
star
50

oas-toolkit

JavaScript
2
star
51

github-action-auto-compile-node

JavaScript
2
star
52

slim-demo

PHP
2
star
53

github-repo-topic

JavaScript
2
star
54

netlify-opengraph-on-demand-builders

JavaScript
2
star
55

github-release-dashboard

CSS
2
star
56

theunixtoolbox.com

CSS
2
star
57

json-schema-spell-checker

This CLI allows you to provide a JSONPath expression and run mdspell against any matching lines.
JavaScript
2
star
58

Silex-Predis

PHP
2
star
59

github-action-readme

JavaScript
2
star
60

github-action-heroku-logs

JavaScript
2
star
61

action-run

Run your Node.js based actions locally
JavaScript
2
star
62

Silex-Rest

Helpers to make building REST API's easier. Handles JSON/XML content types automatically
PHP
2
star
63

Silex-Mandango

PHP
2
star
64

debug-artifact

Save the event payload and `env` from a GitHub action run and easily download them
JavaScript
2
star
65

url-tagger

JavaScript
2
star
66

github-repos-csv

Generate a CSV list of your GitHub repos
JavaScript
2
star
67

vimrunner-php

PHP
1
star
68

terraform-duplicate-checker

Go
1
star
69

kitchen-ansible-docker-example

Example repo of how to test an Ansible playbook using kitchen-ansible and Docker
Ruby
1
star
70

github-action-csharp-example

C#
1
star
71

reviewed-by-trailer-action

JavaScript
1
star
72

cascading-merge-action

JavaScript
1
star
73

jsondiff

Diff two pieces of JSON and receive a verbose explanation of any differences
PHP
1
star
74

dotfiles

Shell
1
star
75

vanguard-funds

JavaScript
1
star
76

payslip4u-downloader

JavaScript
1
star
77

github-action-debug

JavaScript
1
star
78

chrome-extension-open-in-blocks

Open the current repository in GitHub Blocks with the development server enabled
JavaScript
1
star
79

twitter-id-to-username

A small web service for looking up the username of everyone that a specific user is following
JavaScript
1
star
80

wait-for-gem-version

JavaScript
1
star
81

Behat-Selenium2-Webdriver-Example

PHP
1
star
82

blocks-openapi

TypeScript
1
star
83

problem-matcher-tester

JavaScript
1
star
84

json-to-oas-component-cli

JavaScript
1
star
85

nexmo-developer

An archive of the old Nexmo Developer site content
HTML
1
star