get-github-default-branch-name

v1.0.0
get github default branch name
github master branch

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
npm i get-github-default-branch-name

Metadata

  • MIT
  • Whatever
  • u/garronej
  • released 10/12/2023

Downloads

Maintainers