“git butts” : Add your own commands to git! With Node!

While I was visiting New York a few weeks ago, I paired on writing arbitrary git commands with Jeff Fowler.

Jeff’s idea was to make a useful command that opens files edited in the last commit based on what you have set as your $EDITOR.

Adding a command like this is super trivial:

Name the script file to the pattern git-COMMAND, ex. git-open

Make sure it’s executable (chmod +x)

Save the file somewhere in your $PATH

… that’s it.

The other cool thing is that since it’s any script, that means you can write it in whatever you want, including Node.js! Behold git butts (which was, in fact, the arbitrary keyword Jeff chose when showing me this trick):

As you can see from git open it makes more sense, process wise, to create git commands associated with doing git things.

But you don’t have to, so let’s make another thing that doesn’t care about git, but is something you might need while you’re using it:

This will print a random encouraging message when you use git encourage. Might be useful 🙂