A core feature of Git is the ability to create aliases. This effectively allows you to customize Git's command set. As a developer, of course, you're going to want to do this.
However, lately I've come across numerous claims stating aliasing core commands is the Right Way to use Git. Unfortunately, even Pro Git aliases core Git commands in their examples.
Regardless, this is not the Right Way.
Why? Two reasons: obfuscation and speed.
Obfuscation
While aliases give us freedom, there's no convention for aliasing core commands. So they're all subjective.
While these commands exhibit our personal flare, they've lost their meaning. Sure git up
sounds cool and might impress your coworkers. But they have no idea what it does and it isn't available on their setup.
Speed
The primary motivation for aliasing core commands is speed. Oh, the need for speed. Anything to save a few keystrokes. But how many keystrokes are you really saving by aliasing core Git comamnds?
Let's compare some common aliases against command completion.
With the exception of git status
, command completion tied or beat aliases. In addition, command completion also completes references and options. So command completion saves keystrokes across all commands, not just aliases.
In the end, aliases are a useful feature. But stop aliasing core Git commands. Instead, use command completion as a clearer and often faster alternative.
Reserve aliases for Git commands you run frequently and require options. For example, here are my current aliases. Two alias long git log
commands and the others compliment Git's command set with additional custom commands.
Update
There seem to be confusion about scope. My suggestion is not to create Git aliases for core Git commands. This includes things like git st
, git co
, git ci
as shorthands for git status
, git checkout
, git commit
respectively. It does not include Git aliases in general or system aliases.
Want to master Git? Getting Git contains over 60 videos covering Git commands as well as scenarios you'll encounter using Git every day.
Latest comments (41)
What about
g phf
forgit push origin HEAD --force
?I use oh-my-zsh, it comes with git aliases that actually save some typing (3 chars mostly) github.com/robbyrussell/oh-my-zsh/...
There is no "right way" when designing your personal workflow. Who cares about "obfuscation" when is my terminal? and speed? really? sometimes having a good mnemonic is more efficient than saving characters
What even?
Why would you make the case to tell people to stop customizing their environment to their liking?
It's not like an alias removes the original command.
Gws, gcf, gca, glg, gri all mean something to me that many might not follow but they improve my workflow.
If someone sits at my machine they can still use normal git commands.
I would take the stance that everyone should experiment with what works for them and opt to stray from the beaten path in their working environment. Everyone has their own approach so this article is entirely subjective.
Have you ever seen the Oh my Zsh aliases? gco, gl, gp, glgg, etc... they're great, I find this post valid for a CI server or some common machine running git, otherwise I agree that my computer my rules, personally I find the aliases very handy.
most importantly
youtube.com/watch?v=CssC-DY4lO8
I know there are some reasons why not to use them, but these 2 are just not valid, you are contradicting yourself.
"git st" has the same meaning as the "status", because they are synomyms--aliases.
What should the coworkers have to do with my setup?
git com+tab contains more keys strokes than "git ci".
What's next, do not setup custom key bindings to my IDE? 😱 (both your reasons can be applied to custom key bindings). It doesn't improve speed (press the same no of keys) and obfuscate (is not the same as default value).
You're right, I don't setup custom key bindings in my IDE. 😂
My only issue with your post is that in the end, you didn't really show a compelling reason not to use aliases. Is there something you left out, maybe?
Hey Jason, thanks for writing the article and doing the tests with characters used etc. I'll bear it in mind, especially when it comes to working in shared environments and helping others to become familiar with git. I'd always assumed that adding some short aliases did save time, and muscle memory will probably mean I do keep using them, but thanks nonetheless.
I've not written anything for dev.to yet, so not sure what sort of article editing controls there are, but if it's possible... how about changing the title to a 'suggestion' rather than a command, and completely avoid using any reference to the right way? I think you've accidentally undermined yourself by appearing to be dogmatic, which is a shame.
Aliases are a point of customization and as such personal. I think this has caused some readers to react to keywords like right way and miss the focus of this post. While the title was indeed for effect, the post, when read closely, presents the argument for being clear while also providing an alternative.
I'm amazed no one has yet confessed to major sin:
:-D
I really like my git aliases and I already built a muscular memory for them. However, I do agree with the article, specially when I'm pairing on another person's computer. I'm so used to my personal setup that I become ineffective in different settings. I'll try to relearn using vanilla git :)
Ha -- I've been saying this since 2013.
You're catching a lot of "I do what I want" in the comments, but I fully support this idea. I expect everyone to be proficient with bare bones git, be able to share scripts, shell history and the likes.
As for those who don't want to type more characters, this two-liner will set you up for tab autocompletion with git... if you're on a Mac with
brew
installed. But there's probably a similar trick for Linux (or it might even be installed by default).You can even use tab completion for branch names now. 🙌
This article isn't stating "don't use git aliases in scripts" it's stating subjectively that completion is better for you.
Even if you alias everything under the sun, in scripts you want to share or work regardless of changes to aliases you can still use the original commands.
Ha. That's a good way to put it. Thanks for reading the full article.
Unfortunately disagree with this one. I think it's down to the users preference if it's on there machine. If it's on a server it's a different story.
I think aliases are a personal choice, someone prefers to use it, and someone prefers to use tab completion.
When I switched from subversion to git, at the beginning I missed the short commands, but finally I started using tab completion.
As author said, aliases are indisposable to run commands with a specific options.
For my daily work, I don't use aliases, but I use "custom" commands for my daily workflow:
git branch-create $JIRA_ISSUE
creates new branch from the right branch with the right name according our rulesgit branch-sync <--rebase>
Merges or rebases branch from the base branch(it's deducted by the branch name)git pr
simple ncurses interface to open a pull requests, you don't need to specify the base branch againgit branch-clean <--remote>
Cleans local/remote branches which has been merged into masterWe have more, but I think these ones may be interesting :D