Skip to content

“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:

  1. Name the script file to the pattern git-COMMAND, ex. git-open
  2. Make sure it’s executable (chmod +x)
  3. 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 🙂

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

  1. hey cool stuff!

    just wanted to point out that you can also do this via aliasing (by editing ~/.gitconfig). you can execute arbitrary stuff in the alias with a bang like so: “butts = !echo butts”

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.