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.
Initiate the git repository if not already initiated, and create the tk branch
$ git-tk init
Create a starting timestamp
Create a stopping timestamp
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
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.
$ git-tk rebase # git will open an editor with the tk branch commits # choose to "edit" or "drop" any commit # Edit the timestamp commit, # this can be a starting or stopping commit # You can use use the date command to help you construct a timestamp $ git-tk rebase "$(date)" # You can also copy and paste the commit message and edit it in place [Git TK] Editing TK History Stopped at 062f80d... [Git TK] Start: Sat Oct 21 18:06:48 PDT 2017 $ git-tk rebase "Sat Oct 21 18:07:48 PDT 2017" $ git-tk log
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.
# ~/.gitconfig ... [alias] tk = !"/path/to/git-tk"