Show the version number of your Rails app using Git

I use Git tags to manage the version numbers of my Rails apps. Every time a new version is ready, I tag the current commit like this1:

git tag -a v2.3 -m "adding version tag v2.3"

My environment.rb file defines a constant to hold this information (in this case “v2.3”):

APP_VERSION = `git describe --always` unless defined? APP_VERSION

This constant simply contains the output of Git describe2. Now I can use it anywhere in my app where I would like to display the version number.


  1. You are using semantic versioning, right? 

  2. The backticks execute a shell command. Here’s more information: http://gist.github.com/4069 

Notes

  1. danielpietzsch posted this