Personal Agency with Git Time Logging

Tracking time worked is unsexy at best, intrusive micro-management at worst. But I think understanding where time is spent lets individuals drive velocity through better choices. We can do this automatically with git hooks.

Terminal

    
$ git log -1
commit 23ccc3b8f980b038536910f96ac2ddaa8e47eae4 (HEAD -> master)
Author: Doug Bridgens 
Date:   Mon Mar 24 09:13:54 2025 +0000

        Fixes typo in githook scripts

        Time spent on fix_githooks: 0d:0h:3m secs=194
  

Knowing how much time is spent changing code in component x, lets us reason about entropy in the system. Showing your team mates that your swanky new AI co-worker enables you to be faster, could help you improve overall team productivity. Maybe you want to see if you’re more effective when using Vim or VSCode, how else could you know than measuring over time?

Time-tracking as a fuzzy element of over-zealous Agile management turns many of us off. But when time-tracking is a tool developers can use for their own benefit, I’m all in for that.

Measure Beats Estimate

Good software development is not about making perfect software. It is about making software that’s good enough for the purpose, for maintainabilty, while not increasing entropy. Neglecting those last two is leaving free development cadence on the table.

It’s taken a lot of trial and error to find a measure that feels a genuine reflection of time spent ‘writing code’. While at the same time wrapped in a process that doesn’t add any overhead.

My measurement spans from creating a new branch to merging that branch. A git hook automatically calculates and writes an entry into the merge commit. That time is, objectively, how long I spent on implementation.

Now, bear in mind that this is still a vague measure of development time. But it’s definitely less vague than guessing before starting the work. It’s meant to highlight the effort of making a change, excluding engineering/thinking time. All things being relatively equal, over a longer period, anomilies pop out.

Anomolies and trends in the data are things we can talk about in practical terms. Such as, “since we started using AI, average branch time is 10% less.” Or, “component X is getting progressively slower to maintain.”

Terminal

    
$ git log | grep Time
    Time spent on feat_githooks        0d:0h:3m   secs=194
    Time spent on fix_githooks         0d:0h:5m   secs=301
    Time spent on refactor_filestore   0d:22h:26m secs=80685
    Time spent on webui_try_now        2d:4h:12m  secs=187925
    Time spent on webui_blog_template  0d:19h:15m secs=69313
  

What’s really useful is being able to summarise work done.

Terminal

    
$ echo; for i in 'integrations webui'; do
value=$(git log --since="1 month ago" | grep Time | grep $i | cut -f2 -d= | paste -s -d+ - | bc | paste -s -ds - | sed -e 's/$/\/60\/60\/24/g'  | bc)
echo "$i: $value days"
done

integrations: 4 days
webui: 2 days
  

It is not perfect, but it is good enough. I have far more realistic knowledge of how long I spend writing code, and where the slop is accumulating. My hope is that this will show the longer term effects of AI-assisted coding as an objective measure.

How It Works

I’ve put the hooks in a public repo so I can pull them in all my projects via a Makefile. If you copy/paste this then redo the spaces as tabs in the for loop.

# Makefile
GIT_TIME_HOOKS= \
        https://raw.githubusercontent.com/thisdougb/git-time-hooks/main/commit-msg \
        https://raw.githubusercontent.com/thisdougb/git-time-hooks/main/prepare-commit-msg

.PHONY: githooks
githooks:
        @cd .git/hooks && \
        for i in $(GIT_TIME_HOOKS); do \
                echo "installing git hook $$i"; \
                curl -sO $$i; \
                chmod +x "`rev;echo $$i | rev | cut -f1 -d'/' | rev`"; \
        done

My feature development workflow begins by creating a new branch. Then I’ll spend time making the change, and commit.

Terminal

    
$ git checkout -b fix_githooks
Switched to a new branch 'fix_githooks'

# some work happens here

$ git commit -am 'Fixes typo in githook scripts'
[fix_githooks 4b7912b] Fixes typo in githook scripts
 2 files changed, 2 insertions(+), 2 deletions(-)
  

On commit the commit-msg hook writes the creation time of the current branch into the commit message. This means we can get the oldest timestamp when work started from any number of people working on their local copy.

When I’m done I switch back to master, and merge the changes.

Terminal

    
$ git checkout master
Switched to branch 'master'
Your branch is up to date with 'origin/master'.

$ git pull
Already up to date.

$ git merge --squash fix_githooks
Updating 4aeeb7a..4b7912b
Fast-forward
Squash commit -- not updating HEAD
 .githooks/commit-msg | 2 +-
 .githooks/pre-push   | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
  

Now when I commit the merge changes, the prepare-commit-msg hook calculates the development time spent and appends it to the commit message.

Terminal

    
$ git commit
[master 23ccc3b] Squashed commit of the following:
 2 files changed, 2 insertions(+), 2 deletions(-)

$ git log -1
commit 23ccc3b8f980b038536910f96ac2ddaa8e47eae4 (HEAD -> master)
Author: Doug Bridgens 
Date:   Mon Mar 24 09:13:54 2025 +0000

        Fixes typo in githook scripts

        Time spent on fix_githooks: 0d:0h:3m secs=194
  

posted by Doug Bridgens, on Mar 28 2025