Copy & Paste your git status logs like a pro

Daniel BeachJuly 10, 2015

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?

TL;DR

git log --pretty="%ad - %s" --date=short --author=username --since=1.weeks --all --no-merges | pbcopy

Git log to the rescue

Running 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 --author=username flag.

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 --no-merges.

To narrow down the list to just the last week of work we’ll specify --since=1.weeks.

And lastly we can copy the whole thing to the clipboard with | pbcopy.

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 source ~/.bash_profile.

Now all you need to do is type today in the command line, and your statuses will be copied to your clipboard.

@danielbeach


More blog articles:


We empower great search teams!

We help teams that use Solr and Elasticsearch become more capable through consulting and training.

Services Training