get-github-default-branch-name

get github default branch name

Usage no npm install needed!

<script type="module">
  import getGithubDefaultBranchName from 'https://cdn.skypack.dev/get-github-default-branch-name';
</script>

README

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