get-github-default-branch-name
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

Get the default branch name of a GitHub repo

The default branch name is no longer master. To avoid things to break it is a good idea to replace in your codebase the hard coded master word and fetch whatever the default branch is dynamically.

This module provide a way to fetch the default branch name synchronously which could save you lots of hours of refactoring.
Of course you should only do the call synchronously if you can't do otherwise.

Previous result are saved so if you call the method multiple time against the same repo the request will be made only once.

Usage

$ npm install --save get-github-default-branch-name
import {
    getGithubDefaultBranchName,
    getGithubDefaultBranchNameSync,
} from "get-github-default-branch-name";

//Prints "develop" because the default branch of garronej/evt is "main" instead of "master"
getGithubDefaultBranchName({
    "owner": "garronej",
    "repo": "evt",
}).then(defaultBranchName => console.log(defaultBranchName));

//Synchronous version, avoid using if possible. Only OK for scripts.

const defaultBranchName = getGithubDefaultBranchNameSync({
    "owner": "garronej",
    "repo": "evt",
});

console.log(defaultBranchName); // Prints "main"

Contribute

npm install
npm run build
npm test

Dependents (1)

Package Sidebar

Install

npm i get-github-default-branch-name

Weekly Downloads

629

Version

1.0.0

License

MIT

Unpacked Size

14.7 kB

Total Files

7

Last publish

Collaborators

  • garronej