(Re)introducing git-dad
After I dropped the
git-recover
script,
@MordodeMaru asked me on
Twitter
if we could have a git dad
command to help you out when you're in a jam:
But when I started thinking about my stepdad and his banter with his
coworkers, I thought that if a git dad
command was really going to
help you out, it would help you when you mistyped the git add
command.
It could bring you a bit of levity... a dad joke!
And what better day than Father's Day to make that happen:
Now when you mistype git add
as git dad
, it will still add your file
to the index, but it will also give you the prize of a dad joke.
All you have to do is grab git-dad
and put it in your PATH
.
I'd love to claim credit for this wonderful addition to the Git ecosystem, but just as I was getting ready to publish this, I did a quick search for "git dad" and I realized that Tim Petterson had already come up with the idea.
And, honestly, I would like to claim that I just happened to have the same idea. That this was totally independent discovery, like Calculus (and almost as important a contribution to humanity). But the truth is that I probably heard him talking about it. Perhaps it was in his awesome talk at Git Merge about aliases this year. Anyway, I'm sure that somewhere I got the idea from him and it stuck in my head, lying dormant until it was resurrected on Twitter.
But why would we need a second version of git dad
? Surely one is enough.
You'll notice that this solution is a bit different than
his solution,
though. If you have an alias that starts with a bang (!
) it will execute
a non-Git command. (Normally, a Git alias just invokes another Git command;
starting your alias with a !
allows you to invoke any command.)
But, if you have an alias that runs a non-Git command, then the alias will
only be executed from the root of the repository's working
directory. So an alias
for !git add
will work from the root of the repository's working directory,
but not if you're inside some folder beneath that.
Using a script instead of an alias will solve this problem.
I did like his idea of using icanhazdadjoke.com instead of hardcoding some dad jokes. It's a bit slower than if they were hardcoded, but let's face it, that extra time spent is totally worth it to have a fresh, neverending supply.
Happy father's day!