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

0.0.4 • 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 massive 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 "develop" 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 "develop"

Contribute

npm install
npm run build
npm test

Install

npm i get-github-default-branch-name

DownloadsWeekly Downloads

1,584

Version

0.0.4

License

MIT

Unpacked Size

14.5 kB

Total Files

8

Last publish

Collaborators

  • garronej