It’s time to fill out your timesheet, again. You’ve put in a full week of work but remembering everything you’ve accomplished can be difficult when you’re jumping between projects.
What if you could just quickly copy your git commits for the week and be done?
git log --pretty="%ad - %s" --date=short --author=username --since=1.weeks --all --no-merges | pbcopy
Git log to the rescue
git log from the command line while within a git directory will give us a history of the commits for our current branch.
Our goal is to get a short list of commit messages that we can paste directly into a status update or time tracking software.
So to narrow down the commit messages to only the commits that we have made we can use the
Then, to create a list of commmit messages with their authored date we specify a format of
--pretty="%ad - %s" --date=short.
We’re getting closer. But it looks like there are a number of merge commits that clutter up the list. We can remove those by adding
To narrow down the list to just the last week of work we’ll specify
And lastly we can copy the whole thing to the clipboard with
Here are a few variations that I’ve found useful:
alias thisWeek='git log --pretty="%ad - %s" --date=short --author=username --since=1.weeks --all --no-merges | pbcopy'alias today='git log --pretty="%s." --author=username --since=midnight --all --no-merges | pbcopy'alias yesterday='git log --pretty="%s." --author=username --since=3.days --until=yesterday --all --no-merges | pbcopy'
You can add these aliases by editing your
~/.bash_profile file and then updating your terminal by
Now all you need to do is type
today in the command line, and your statuses will be copied to your clipboard.