How do I print a list of my git aliases, i.e., something analogous to the bash alias command?
I use this alias in my global ~/.gitconfig
# ~/.gitconfig
[alias]
aliases = !git config --get-regexp ^alias\\. | sed -e s/^alias.// -e s/\\ /\\ $(printf \"\\043\")--\\>\\ / | column -t -s $(printf \"\\043\") | sort -k 1
to produce the following output
$ git aliases
aliases --> !git config --get-regexp ^alias\. | sed -e s/^alias.// -e s/\ /\ $(printf "\043")--\>\ / | column -t -s $(printf "\043") | sort -k 1
ci --> commit -v
cim --> commit -m
co --> checkout
logg --> log --graph --decorate --oneline
pl --> pull
st --> status
... --> ...
(Note: This works for me in git bash on Windows. For other terminals you may need to adapt the escaping.)
!git config --get-regexp ^alias\\. prints all lines from git config that start with alias.sed -e s/^alias.// removes alias. from the linesed -e s/\\ /\\ $(printf \"\\043\")--\\>\\ / replaces the first occurrence of a space with \\ $(printf \"\\043\")--\\> (which evaluates to #-->).column -t -s $(printf \"\\043\") formats all lines into an evenly spaced column table. The character $(printf \"\\043\") which evaluates to # is used as separator.sort -k 1 sorts all lines based on the value in the first column$(printf \"\043\")
This just prints the character # (hex 043) which is used for column separation. I use this little hack so the aliases alias itself does not literally contain the # character. Otherwise it would replace those # characters when printing.
Note: Change this to another character if you need aliases with literal # signs.