DEV Community

Discussion on: The case against aliases

Collapse
 
ferdnyc profile image
Frank Dana

It's worth noting, also, that git aliases are (or should be) aliased within git, as it adds a lot of nice features:

$ git alias
unstage = reset HEAD --

$ git unstage --help # or
$ git help unstage
'unstage' is aliased to 'reset HEAD --'

$ git unstag
git: 'unstag' is not a git command. See 'git --help'.

The most similar command is
    unstage
Enter fullscreen mode Exit fullscreen mode

That's a lot less terribad than wrapping the same thing in a shell alias or function. Shell aliases for git commands are especially dumb because you're both circumventing many of git's better features, and creating something that's susceptible to all of the issues raised here.

(It's almost as if, knowing their command structure might be... let's say "less than intuitive", the git developers at least decided to include good tools for mitigating that problem.)

Collapse
 
pbnj profile image
Peter Benjamin (they/them) • Edited

I have also seen some really long/complex-looking git aliases that are really hard to follow, like:

[alias]
  foo = !"f() { some; really && long | function onliner || with lots of $(sed) && awk '{print $1}' && then call --it at 'the' end ; } ; f"
Enter fullscreen mode Exit fullscreen mode

For these cases, I would recommend creating an executable script placed somewhere in your $PATH named git-foo and git will expose this as a subcommand, like $ git foo. Just like git-extras.

Thread Thread
 
ferdnyc profile image
Frank Dana

Agreed, as an alias abuse that's just obnoxious.

Collapse
 
ferdnyc profile image
Frank Dana

Actually I guess git alias is part of git-extras, not core git. I guess I never noticed before, since it's just sort of always been there.