{"id":13656636,"url":"https://github.com/kevinoid/git-branch-is","last_synced_at":"2025-05-16T12:07:13.671Z","repository":{"id":4356207,"uuid":"51800497","full_name":"kevinoid/git-branch-is","owner":"kevinoid","description":"Assert that the name of the current branch of a git repository has a particular value.","archived":false,"fork":false,"pushed_at":"2024-11-02T19:29:09.000Z","size":1100,"stargazers_count":95,"open_issues_count":2,"forks_count":9,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-02T07:41:27.616Z","etag":null,"topics":["cli","git","nodejs"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kevinoid.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-02-16T02:04:58.000Z","updated_at":"2025-03-12T16:14:40.000Z","dependencies_parsed_at":"2023-07-05T20:16:12.831Z","dependency_job_id":"ab8da4d0-0317-4349-be3b-daa4264357f0","html_url":"https://github.com/kevinoid/git-branch-is","commit_stats":{"total_commits":511,"total_committers":5,"mean_commits":102.2,"dds":0.07436399217221135,"last_synced_commit":"527eec0f3972099a574a330ada44efd2b44a80d9"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kevinoid%2Fgit-branch-is","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kevinoid%2Fgit-branch-is/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kevinoid%2Fgit-branch-is/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kevinoid%2Fgit-branch-is/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kevinoid","download_url":"https://codeload.github.com/kevinoid/git-branch-is/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248008628,"owners_count":21032556,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cli","git","nodejs"],"created_at":"2024-08-02T05:00:27.780Z","updated_at":"2025-04-09T09:02:42.893Z","avatar_url":"https://github.com/kevinoid.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"`git-branch-is`\n===============\n\n[![Build Status](https://img.shields.io/github/actions/workflow/status/kevinoid/git-branch-is/node.js.yml?branch=main\u0026style=flat\u0026label=build)](https://github.com/kevinoid/git-branch-is/actions?query=branch%3Amain)\n[![Coverage](https://img.shields.io/codecov/c/github/kevinoid/git-branch-is/main.svg?style=flat)](https://app.codecov.io/gh/kevinoid/git-branch-is/branch/main)\n[![Dependency Status](https://img.shields.io/librariesio/release/npm/git-branch-is.svg?style=flat)](https://libraries.io/npm/git-branch-is)\n[![Supported Node Version](https://img.shields.io/node/v/git-branch-is.svg?style=flat)](https://www.npmjs.com/package/git-branch-is)\n[![Version on NPM](https://img.shields.io/npm/v/git-branch-is.svg?style=flat)](https://www.npmjs.com/package/git-branch-is)\n\nAssert that the name of the current branch of a git repository has a particular value.\n\n## Introductory Example\n\nTo check that the current branch is named `release` and print an error if not,\nrun the following command:\n\n```\n$ git-branch-is release\nError: Current branch is \"main\", not \"release\".\n$ echo $?\n1\n```\n\nThis can be useful as part of a [`preversion`\nscript](https://docs.npmjs.com/cli/version) in `package.json`:\n\n```json\n{\n  \"name\": \"super-cool-package\",\n  \"version\": \"1.2.3\",\n  \"scripts\": {\n    \"preversion\": \"git-branch-is release \u0026\u0026 echo Preversion checks passed.\"\n  }\n}\n```\n\n## Installation\n\n[This package](https://www.npmjs.com/package/browserify) can be installed\nusing [npm](https://www.npmjs.com/), either globally or locally, by running:\n\n```sh\nnpm install git-branch-is\n```\n\n## Command Usage\n\nThe command options are intended to be similar to `git` and are documented in\nthe `--help` output:\n\n```\nUsage: git-branch-is [options] \u003cbranch name\u003e\n\nOptions:\n  -C \u003cpath\u003e           run as if started in \u003cpath\u003e\n  --git-arg \u003carg\u003e     additional argument to git (can be repeated) (default: [])\n  --git-dir \u003cdir\u003e     set the path to the repository\n  --git-path \u003cpath\u003e   set the path to the git binary\n  -i, --ignore-case   compare/match branch name case-insensitively\n  -I, --invert-match  inverts/negates comparison\n  --not               inverts/negates comparison (same as --invert-match)\n  -q, --quiet         suppress warning message if branch differs\n  -r, --regex         match \u003cbranch name\u003e as a regular expression\n  -v, --verbose       print a message if the branch matches\n  -V, --version       output the version number\n  -h, --help          output usage information\n```\n\n## Additional Command Examples\n\n### Regular Expression Matching\n\nTo check that the current branch starts with `release/` using a regular\nexpression:\n\n```\n$ git-branch-is -r \"^release/\"\nError: Current branch \"main\" does not match \"^release/\".\n$ echo $?\n1\n```\n\nNote:  Be careful to quote patterns to avoid shell expansion or special\nhandling (e.g. POSIX shells expand `*` and `cmd.exe` treats `^` specially).\n\n### Case-Insensitive Matching\n\nTo check that the current branch starts with `release/` case-insensitively\nusing a regular expression:\n\n```\n$ git-branch-is -i -r \"^release/\"\nError: Current branch \"main\" does not match \"^release/\".\n$ echo $?\n1\n```\n\n### Inverted/Negated Matching\n\nTo check that the current branch is not `main`, use `-I`, `--invert-match`,\nor `--not` (all functionally equivalent, use whichever you prefer):\n\n```\n$ git-branch-is --not main\nError: Current branch is \"main\".\n$ echo $?\n1\n```\n\n## API Usage\n\nTo use the API with a callback function:\n\n```js\nconst gitBranchIs = require('git-branch-is');\ngitBranchIs('main', function(err, result) {\n  if (err) console.error(err);\n  else console.log(result ? 'On main' : 'Not on main');\n});\n```\n\nAlternatively, if a callback is not provided, `gitBranchIs` will return a\n`Promise`:\n\n```js\nconst gitBranchIs = require('git-branch-is');\ngitBranchIs('main').then(\n  function(result) { console.log(result ? 'On main' : 'Not on main'); },\n  function(err) { console.error(err); }\n);\n```\n\nAdditionally, instead of a string, a checking function can be passed to\nperform arbitrary checking against the branch name:\n\n```js\nconst gitBranchIs = require('git-branch-is');\ngitBranchIs(function(branchName) { /^main$/.test(branchName); }).then(\n  function(result) { console.log(result ? 'On main' : 'Not on main'); },\n  function(err) { console.error(err); }\n);\n```\n\n## API Docs\n\nTo use this module as a library, see the [API\nDocumentation](https://kevinoid.github.io/git-branch-is/api).\n\n## Rationale\n\nWhat's the value of this command over scripting with `git` directly?  Good\nquestion.  The [Introductory Example](#introductory-example) could instead be\napproximated with the following:\n\n```json\n{\n  \"name\": \"super-cool-package\",\n  \"version\": \"1.2.3\",\n  \"scripts\": {\n    \"preversion\": \"if [ \\\"$(git symbolic-ref HEAD)\\\" = release ] ; then echo Preversion checks passed. ; else echo Error: Not on branch release. ; exit 1 ; fi\"\n  }\n}\n```\n\nFor packages which are only targeting POSIX systems, this may be a preferable\nsolution.  However, it doesn't work on systems which don't support the POSIX\nshell language (e.g. Windows, which runs scripts in `cmd.exe`).  To support\nthese systems it is necessary to either introduce a dependency on Bash, to\nuse this script, or code up something else.\n\n## Contributing\n\nContributions are appreciated.  Contributors agree to abide by the [Contributor\nCovenant Code of\nConduct](https://www.contributor-covenant.org/version/1/4/code-of-conduct.html).\nIf this is your first time contributing to a Free and Open Source Software\nproject, consider reading [How to Contribute to Open\nSource](https://opensource.guide/how-to-contribute/)\nin the Open Source Guides.\n\nIf the desired change is large, complex, backwards-incompatible, can have\nsignificantly differing implementations, or may not be in scope for this\nproject, opening an issue before writing the code can avoid frustration and\nsave a lot of time and effort.\n\n## License\n\nThis project is available under the terms of the [MIT License](LICENSE.txt).\nSee the [summary at TLDRLegal](https://tldrlegal.com/license/mit-license).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkevinoid%2Fgit-branch-is","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkevinoid%2Fgit-branch-is","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkevinoid%2Fgit-branch-is/lists"}