Git Time Keeper
Keeping track of time is important when programming. Git records the date and time of each commit you perform, but extracting the amount of time you spent on a commit or task is impossible. There are currently a few time trackers that integrate with git but are arduous to install and overly complex.
Here comes Git Time Keeper to the rescue. Git Time Keeper is a bash script that uses a separate branch in your git history to keep track of the time you’ve spent working. You can create starting and stopping timestamps at your discretion as well as rebase those timestamps to add, remove, or edit them.
Click here to go to the Github repository
Initiate the git repository if not already initiated, and create the tk branch
$ git-tk init
Create a starting timestamp
$ git-tk
Create a stopping timestamp
$ git-tk
Show a log of the timestamps
$ git-tk log
Create a starting timestamp at a specific time
$ git-tk "$(date)"
Create a stopping timestamp at a specific time
$ git-tk "$(date)"
Rebase the Time Keeper history
$ git-tk rebase
Documentation
Git Time Keeper creates empty commits on a branch called tk. You create these commits manually so there’s no need to run a server that keeps track of activity. If there are more starting time commits, then git-tk will create an ending time commit. If there are an equal number of starting and ending time commits, then git-tk will create a starting time commit. Git-tk log will list your repository commits surrounded by your git-tk timestamps. This makes it easy to see what you did and when.
Rebasing uses plain old git interactive rebase. You simply mark the timestamps you want to edit with “edit” or “e” when git lists the commits in your chosen editor. Close the editor and run git-tk rebase again with a timestamp and the timestamp will be updated. You can also remove timestamp commits using git-tk rebase and choosing “drop” or “d” when git lists the commits in your chosen editor. While rebasing, running git-tk rebase with no timestamp will skip the current commit.
Install
To install git-tk you will simply place the bash script anywhere on your system. You then create an alias in your gitconfig that will execute git-tk.
To Use
###########################
# Initialize the tk branch
###########################
# Git must be initialized with at least one commit
$ git init
$ git commit --allow-empty -m "Initial Commit"
# Initialize the git-tk branch
$ git-tk init
###########################
# Start and stop the timer
###########################
# Create a starting timestamp
$ git-tk
# Do some work
$ git commit --allow-empty -m "Test commit"
# Create an ending timestamp
$ git-tk
###########################
# Change the timestamps
###########################
# This command will initiate rebasing interactively
# It will also continue/skip during the rebase
$ git-tk rebase
# Now, select the timestamps you'd like to edit
# by changing 'pick' to one of 'edit' or 'reword'
# For each timestamp you are changing,
# run this command with your chosen timestamp
# You can also copy, paste and edit the timestamp from
# the output of git status
$ git-tk rebase "$(date)"
##############################
# Placing arbitrary timestamps
##############################
# Do some work
$ git commit --allow-empty -m "Test commit"
# Create a starting timestamp manually
$ git-tk "$(date -d '10 minutes ago')"
# Create an ending timestamp manually
$ git-tk "$(date -d '5 minutes ago')"
###############################
# Viewing the log of timestamps
###############################
# List commits with timestamps in an easy to read format
$ git-tk log
# List whole commits with timestamps in an easy to read format
$ git-tk log -v
Using Git Alias
# ~/.gitconfig
...
[alias]
tk = !"/path/to/git-tk"