Shell Tricks: One Git Alias to Rule Them All

Continuing the Shell Tricks series, here’s a handy Git trick. I’ll be moving away from the Git tips soon, so don’t lose heart if you love the command line but aren’t a big Git fan.

When I discover cool new Git commands, I tend to alias them in my global .gitconfig file to help me remember how to use them. You can see what any alias is by running with git help aliasname, so when I use them I like to check that and start memorizing the actual commands. Sometimes, though, I’ll know I figured out a trick but can’t remember what it’s aliased as. Then I have to list all of my aliases, grep for the one containing the base command I’m looking for, and then work to memorize that.

Here’s a trick for doing all of that at once. First, we use the git config command to list all of our aliases, which is pretty simple:

There’s probably a simpler awk command to do the separation part, but I kept running into problems using substr() in the awk command so defaulted to a for loop. You can also simplify it using a cut command instead, but it doesn’t work with the next part.