Setting up git with Rescuetime highlights

Shane Dowling
Feb 15, 2015 · 2 min read
Image for post
Image for post

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 ]
API_KEY=PUT_YOUR_API_KEY_HERE# REQUIRED FIELDS - Today's date and commit messageMESSAGE=$(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 README.mdif [[ ${#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.

Tech Blog

Random smattering of technical posts

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store