https://github.com/garronej/get-github-default-branch-name
Get the default branch name of a given repo
https://github.com/garronej/get-github-default-branch-name
Last synced: about 1 month ago
JSON representation
Get the default branch name of a given repo
- Host: GitHub
- URL: https://github.com/garronej/get-github-default-branch-name
- Owner: garronej
- License: mit
- Created: 2020-06-20T15:41:53.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2023-10-12T16:36:40.000Z (over 1 year ago)
- Last Synced: 2025-05-07T08:03:22.407Z (about 1 month ago)
- Language: TypeScript
- Homepage:
- Size: 174 KB
- Stars: 2
- Watchers: 2
- Forks: 2
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
![]()
Get the default branch name of a GitHub repo
![]()
![]()
[The default branch name is no longer `master`](https://www.bbc.com/news/technology-53050955). 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
```bash
$ npm install --save get-github-default-branch-name
``````typescript
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
```bash
npm install
npm run build
npm test
```