Joshua Wood Web Developer

How to get the latest Git commit SHA

Some monitoring tools—such as honeybadger.js—need the latest Git commit SHA/hash for reporting purposes. Here’s a simple way to get it, assuming you are building or deploying from inside your Git repository:

GIT_REVISION=$(git rev-parse HEAD) \
  npm build # your normal build command (could also be yarn, webpack, etc.)```

The `GIT_REVISION` environment variable can be accessed via `process.env.GIT_REVISION` in Node.js, `ENV["GIT_REVISION"]` in Ruby, etc.