# version-from-git

> Bump package.json version to pre-release tagged with Git branch and short commit hash, 1.0.0-main.1a2b3c4

Latest version **1.2.0** (published 2025-12-24) · MIT license · 0 weekly downloads

## Install

```sh
npm install version-from-git
pnpm add version-from-git
yarn add version-from-git
bun add version-from-git
```

Provides the command `version-from-git`.

## Health

**Score 65/100 (B)** — status: stable.

Positive: has types; esm support; no vulnerabilities; has provenance; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 1.2.0 |
| Published | 2025-12-24 |
| First published | 2018-05-18 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 8 |
| Unpacked size | 16.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 8 |
| Author | William Wong |
| Maintainers | compulim, spyip |
| Keywords | branch, bump, ci, commit, git, travis, version |

## Links

- npm: https://www.npmjs.com/package/version-from-git
- Repository: https://github.com/compulim/version-from-git
- Homepage: https://github.com/compulim/version-from-git#readme
- Issues: https://github.com/compulim/version-from-git/issues
- npm.io page: https://npm.io/package/version-from-git

## Dependencies (8)

- [chalk](https://npm.io/package/chalk.md) ^5.6.2
- [semver](https://npm.io/package/semver.md) ^7.7.3
- [read-pkg](https://npm.io/package/read-pkg.md) ^10.0.0
- [commander](https://npm.io/package/commander.md) ^14.0.2
- [cross-spawn](https://npm.io/package/cross-spawn.md) ^7.0.6
- [git-rev-sync](https://npm.io/package/git-rev-sync.md) ^3.0.2
- [version-from-git](https://npm.io/package/version-from-git.md) ^1.2.0
- [on-error-resume-next](https://npm.io/package/on-error-resume-next.md) ^2.0.3

## Alternatives

- [random-seedable](https://npm.io/package/random-seedable.md) — 27.9K weekly downloads
- [n2words](https://npm.io/package/n2words.md) — 22.2K weekly downloads
- [@stdlib/math-base-special-factorialln](https://npm.io/package/@stdlib/math-base-special-factorialln.md) — 5.7K weekly downloads
- [@stdlib/math-base-special-abs2](https://npm.io/package/@stdlib/math-base-special-abs2.md) — 1.7K weekly downloads
- [commons-math-interpolation](https://npm.io/package/commons-math-interpolation.md) — 1.4K weekly downloads

## Recent versions

- 1.2.0 (latest) — 2025-12-24
- 1.2.1-main.202601022250.bc54a64 (main) — 2026-01-02
- 1.1.2-master.9b49011 (master) — 2019-08-12
- 1.2.1-main.202512240318.67492b7 — 2025-12-24
- 1.1.3-main.202512240313.452912f — 2025-12-24
- 1.1.3-main.202512240308.e36305c — 2025-12-24
- 1.1.3-main.7f05109 — 2024-10-13
- 1.1.3-main.8eda114 — 2024-10-13
- 1.1.3-main.624d714 — 2024-10-12
- 1.1.3-main.46c1aad — 2024-07-05
- 1.1.3-main.0d4fa05 — 2024-06-29
- 1.1.3-main.98ff1b7 — 2024-05-25
- 1.1.3-main.387c948 — 2024-05-24
- 1.1.2 — 2024-05-24
- 1.1.2-main.320b9e4 — 2024-05-24
- … 17 more at https://npm.io/package/version-from-git/versions

## README

# version-from-git

[![npm version](https://badge.fury.io/js/version-from-git.svg)](https://badge.fury.io/js/version-from-git)

# Background

We want to use `npm version` to bump to a customized version that contains both Git branch and commit hash.

And use Travis CI to automatically publish the pre-release version to NPM, tagged using [`npm dist-tag`](https://docs.npmjs.com/cli/dist-tag).

> Instead of using plus (+) to denote build information, we prefer period (.) for simpler escapes. If you prefer the plus sign, you can [customize the pre-release version pattern](#customizing-pre-release-version-pattern).

# How to use

Run `npx version-from-git`, it will run `npm version 1.0.0-main.1a2b3c4`.

```
  Usage: version-from-git [options]

  Bump package.json version to pre-release tagged with Git branch and short commit hash, 1.0.0-main.1a2b3c4

  Options:

    -V, --version            output the version number
    -p, --path <path>        path to package.json, default to current directory (default: C:\Users\Compulim\Source\Repos\version-from-git)
    --template <template>    pre-release version template (default: branch.short)
    -t, --travis             run in Travis CI: skip when TRAVIS_TAG present
    -f, --force              run "npm version" with --force
    -m, --message <message>  run "npm version" with --message
    --allow-same-version     run "npm version" with --allow-same-version
    --sign-git-tag           run "npm version" with --sign-git-tag
    --no-commit-hooks        run "npm version" with --commit-hooks
    --no-git-tag-version     run "npm version" with --no-git-tag-version
    -h, --help               output usage information
```

## How to use under Travis

In Travis, when you push a tag (probably by `npm version 1.0.0` followed by `git push origin v1.0.0`), you may want to skip `version-from-git` from generating a pre-release tag.

Run `npx version-from-git -t`, it will detect whether `TRAVIS_TAG` environment variable is present and skip.

## Customizing pre-release version pattern

You can customize the version pattern when tagging for pre-release versions by running with argument `--template branch.short`.

| Pattern name | Description                                                      | Sample                                     |
| ------------ | ---------------------------------------------------------------- | ------------------------------------------ |
| `branch`     | Branch name<br />In Travis, will use `process.env.TRAVIS_BRANCH` | `main`                                     |
| `long`       | Git commit in long form                                          | `3807f9004867438c57a3e26f2073c33c458d4ef9` |
| `short`      | Git commit in short form                                         | `3807f90`                                  |

Default pattern is `branch.short`, which would produce `main.1a2b3c4`.

# Contributions

Like us? [Star](https://github.com/compulim/version-from-git/stargazers) us.

Want to make it better? [File](https://github.com/compulim/version-from-git/issues) us an issue.

Don't like something you see? [Submit](https://github.com/compulim/version-from-git/pulls) a pull request.

---
_Source: https://npm.io/package/version-from-git · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
