Setting up git with Rescuetime highlights

Recently I've written on another site how I use Rescuetime to provide metrics on my overall productivity that I can review each week. One useful feature I noticed was Rescuetime highlights, which gives you a good overview of your accompishments throughout the day. The first thing I wanted to add to this (obviously) was git commits.

Luckily it turns out someone had already thought of this and implemented it. The script itself is here, I'm just going to reproduce it below.

# An example hook script to log commit messages
# as a 'daily highlight' in RescueTime Premium
# See for more information
# To enable this hook:
# 1. Place this file in .git/hooks and rename to "post-commit".
# 2. Update the value of API_KEY below with a valid RescueTime API key.
#    [ you can generate a key at []( ]


# REQUIRED FIELDS - Today's date and commit message

MESSAGE=$(git log -1 HEAD --pretty=format:%s)
DATE_TODAY=$(date +"%Y-%m-%d")

# You can edit the LABEL value if you would rather
# describe these commits differently.

LABEL='Code Commit'

# See more filtering examples in

if [[ ${#MESSAGE} -gt 16 ]]; then
  curl --data "key=$API_KEY&highlight_date=$DATE_TODAY&description=$MESSAGE&source=$LABEL" [](

Now, the annoying part for me is that this doesn't work globally across all of my git repos, so to fix this you can leverage git's templates directory. To create/initialise a git template folder simply run these commands.

git config — global init.templatedir '~/.git_template'
mkdir -p ~/.git-templates/hooks

Then put the above shell code into ~/.git-templates/hooks/post-commit

What this means is that from now on, any new git repos you initialise will contain this post-hook script. However, if you want to attach this to existing repos, just run a git init wherever the .git folder is.