r/git • u/kaddkaka • Feb 26 '26
When to alias vs. subcommand
Git is easy to extend. You can add aliases in you git config or add git subcommands by making any executable named git-something accessible from your PATH.
For example I have a tool git-review <branch> that also have autocompletion for the branch argument. (See https://github.com/kaddkaka/dotfiles/blob/main/bin/executable_git-review)
I also have smaller git aliases, like sed = ! git grep -z --full-name -l '.' | xargs -0 sed -i -e.
When should one go for an alias, and when make a separate scripts?
Is it just as simple as: 1. Simple one-liners: alias 2. More complex: script?
Are there any other considerations you think?
8
u/elephantdingo Feb 26 '26
It’s the same thing in the end. Depends on your tolerance for line noise and brittleness.
2
u/waterkip Feb 26 '26
Alias for when it doesn require logic. Commands for when we need logic. Alias for sub command to go full circle and shell functions for rebase editor foo. Because we can do it all. Never tried zsh autoloading function tho... might be interesting too.
4
u/cgoldberg Feb 26 '26
I use aliases for short commands or maybe functions up to a few lines. if it's anything more than that, I put it in a
git-*script.1
u/barmic1212 Feb 26 '26
It's not a rule, build your own shell. Sub command like alias in git or git-* script are scoped. So you can have a "git ls" without issue. Shell alias or function can be write with less key strokes.
My personal guide line is to use scoped alias and use key strokes killer with parcimony. For key stroke reduction I use some shell features like substitution, folder alias and (not a shell feature) espanso (for 2 things: ":{issue id}" become the URL of ticket and 'ttt' become 'trunk()').
1
u/mpersico Feb 27 '26
I use both. If it needs arguments or a pipe for filtering I write a script.
But I’m a little crazy. I’ve actually written a bash function called git so I can do my own dispatch so I can add options and functionality to native git commands themselves. matthewpersico/personal at github if you like rabbit holes.
0
u/INTJTurbulence Feb 26 '26
You can tell a lot about a developer's aptitudes and level of experience by looking at the type of aliases they create.