Git Aliases vs. Shell Aliases

General Remarks

Using git aliases saves some time in typing. Generally this is a good idea, if the aliases save enough time and if the aliases are used often enough to be remebered. On the other hand, even with git aliases you need to type the git command itself.

If you use git a lot, as I do, I think that even typing the git command needs to much time.

For example it might make sense to set the git-alias wddiff like this:
git config alias.wddiff 'diff --word-diff'

This saves typing time, because instead of
git diff --word-diff
you can just type
git wddiff

Still too much typing for the Basics

On the other hand: wheny you just want the default git-diff command, you still have to type it completely:
git diff
which I think is too much of typing. So what I do instead is a shell alias (I am using bash) like this:
alias d="git diff"
which saves me the most typing, because I use the normal git diff most of the time and extremely often. And now I only have to type d.

When I then need to add extra options (less frequently used), I just type them, or additionally create an alias for git, or if it makes sense, just another shell-alias.
What I used for a while then was: d --staged
But because I used this command also very frequently, I later added a ds shell alias for this too.

Instead of git last (proposed here: scm git-book on aliases) I just type
l -1
because I have the following shell-alias:
alias l="git log"

Proposing aliases

Many tips for git aliases are given in many vidoes you can find on (for example) youtube. Most of these advocated aliases don't make any sense to me. People have very different thinking and taste. And because of the above mentioned shell-aliases I have not many git aliases.

Some git aliases I use

Even I think proposing certain aliases to people is not working most of the time (because of different thinking, taste and needs), and git aliases are most of the time not saving me enough of the typing, there is a small number of git aliases I use.

And here are those I found mostly useful:
Relatively often used and very helpful:
git config alias.stashki 'stash --keep-index'

The next one I need sometimes. It is very helpful if you are somewhere deep in the directory structure and want to git-grep as if you would be in the toplevel directory of your git repo.
git config alias.grepall '!git grep'

And if you need to know the absoulte path to the toplevel directory of the repository you are in, the following is very useful:
git config alias.root 'rev-parse --show-toplevel'

global git aliases?

All the above mentioned aliases id not use the --global switch. This is, because I'm still not convinced to use these git-aliases all the time in all repositories. I tend to add them locally.
My taste on this may vary over time. If you tend to use all your aliases generally in all your repositories, feel free to add this flag to all alias-definitions mentioned above.

Oliver Bandel, 2025-04-27