Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ScottJWalter/7977b5603b4d7851bbbabff29a130f29 to your computer and use it in GitHub Desktop.
Save ScottJWalter/7977b5603b4d7851bbbabff29a130f29 to your computer and use it in GitHub Desktop.
Automatic version numbers of your git repository using git hooks

Put this in a file called pre-commit in .git/hooks/

#!/bin/sh
# To enable this hook, rename this file to "pre-commit".

git log master --pretty=oneline | wc -l > build_number
git add build_number

Now there is a file called build_number in the root of your directory that counts the number of commits on your master branch (which is your build number).

Make sure the permissions on the file you created are the same as the samples in that directory.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment