You can add a git sub-command by defining a new alias in your ~/.gitconfig file as follows:

This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters

[Show hidden characters]({{ revealButtonHref }})

[alias]
open = !vim git-open.sh

view raw gitconfig hosted with ❤ by GitHub

The git open defined in the ~/.gitconfig is mapped to a shell script called git-open.sh. 

This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters

[Show hidden characters]({{ revealButtonHref }})

#!/bin/bash
dirty=`git status –porcelain -uno
last_modified=git show --pretty="format:" --name-only HEAD
if [ -n “$dirty” ]; then
echo $dirty
else
echo $last_modified
fi

view raw git-open.sh hosted with ❤ by GitHub

This bash script does two things: 

  1. It tries to detect if there are any files with uncommitted changes in the current repo and prints out the filenames.

  2. If the repo doesn’t have any uncommitted files, it’ll print the filenames from the last commit.

The git open alias is mapped to open the output from this script using vim. 

Why is this useful?

I can pick up where I left off the previous day by simply typing git open inside the repo. This will open either all files with uncommitted changes or open the files from the last commit. There is a very good chance that my work for the day will continue on those files.

A small hack to make life a little bit easier.