How to List All Git Aliases


How can we list all available Git aliases on our system?

All of our aliases are stored in ~/.gitconfig, so the question becomes: what is the simplest or fastest way to pull the aliases from this file?

View ~/.gitconfig

Our first option is to simply view this file in a text editor, vim, or just output the file contents to the terminal.

cat ~/.gitconfig

Our aliases will reside under the [alias] section.

Read everything in git config

We can also dump all of our Git configurations into the terminal using git config, and then use our eyes to find the aliases.

git config --global --list

The aliases will look something like this.

alias.alias_name=the_command_we_do_not_want_to_write_out

Read only aliases from git config

We can also view our Git aliases by only returning lines that match the format of a Git alias.

git config --get-regexp '^alias\.'

The regular expression ^alias\. matches all lines that start with the word alias and contain a single period . afterward.

Create another alias

Finally, we can create another alias to list our aliases.

Let’s steal the command from earlier, and place it in an alias called aliases.

git config --global alias.aliases "config --get-regexp '^alias\.'"

We can then use this alias to find all of our other aliases.

git aliases