612

How do I print a list of my git aliases, i.e., something analogous to the bash alias command?

Asclepius
  • 57,944
  • 17
  • 167
  • 143
ma11hew28
  • 121,420
  • 116
  • 450
  • 651

24 Answers24

655

You can use --get-regexp with the regular expression ^alias, ie all configurations that start with alias

git config --get-regexp ^alias
CervEd
  • 3,306
  • 28
  • 25
William Pursell
  • 204,365
  • 48
  • 270
  • 300
  • 53
    To be pedantic, that should be `'^alias\.'` – Josh Lee Aug 15 '11 at 16:12
  • 49
    `git config -e` edits the `.git/config` file only. But most of my aliases are defined in the global `~/.gitconfig`. – Boldewyn May 09 '12 at 07:38
  • 29
    To be practical, that should be `git config --global alias.aliases config --get-regexp '^alias\.'"` ... and then `git aliases` – Derek Greer Oct 09 '14 at 13:52
  • 9
    @DerekGreer you're missing a `"` somewhere – Jake Berger Feb 06 '15 at 10:42
  • Or `aliases=config --get-regexp '^alias\\.'` in the .gitconfig – vp_arth Nov 16 '15 at 09:30
  • 10
    `git config --global alias.aliases "config --get-regexp '^alias\.'"` and then `git aliases` – Ondra Žižka Jan 01 '17 at 22:10
  • 2
    @MatrixFrog some people always start a big dialog wiht plenty of information to look through even if it is not necessary instead of using tools like regex to reduce workload beforehand ;-) – codingdave Mar 15 '17 at 12:38
  • 1
    `git config --global --list` – djvg Dec 12 '18 at 08:48
  • `git config --global alias.cfgg 'config --global'` then `git cfgg alias.ls-alias "config --get-regexp '^alias\.'"` – Josh Gust Dec 12 '18 at 22:39
  • @DerekGreer I'd remove `--global`, it restricts to only global aliases – CervEd Oct 20 '22 at 09:28
  • @CervEd The command `git config --global --get-regex '^alias\.'` will only show you the aliases defined in global config, but the command `git config alias.aliases "config --get-regexp '^alias\.'"` will only define an alias that will show you all aliases for your current repo. You want the "show me all the things" defined in the global config, therefore you want `git config --global alias.aliases "config --get-regexp '^alias\.'"`. – Derek Greer Oct 24 '22 at 19:14
  • @DerekGreer `git config --global --get-regex '^alias\.'` will display global aliases _only_, whereas `git config --get-regex '^alias\.'` will display global _and_ local aliases. What you want may differ. Personally, I want to see both. Possibly only the one that wins (local alias) `git config --get-regex '^alias\.' | tac | sort -u -t ' ' -k1,1 ` in case of collision – CervEd Oct 24 '22 at 20:23
  • You're missing it, guy. Completely forget for a minute *what* you want the alias to do and ask your self, _where do I want to be able to use this alias?_. If you are in repo "~/projects/my_repo" and you issue the command `git config alias.xyz log`, you'll be able to do a `git xyz` in the repo "~/projects/my_repo", but you won't be able to use it outside of that folder. If you want to configure an alias that isn't repo specific (i.e. you can use the aliases everywhere), you want to use `--global`. The global is where the alias gets created, not a limit where the aliases are read. – Derek Greer Oct 24 '22 at 20:42
211

This answer builds upon the answer by johnny. It applies if you're not using git-alias from git-extras.

On Linux, run once:

git config --global alias.alias "! git config --get-regexp ^alias\. | sed -e s/^alias\.// -e s/\ /\ =\ /"

This will create a permanent git alias named alias which gets stored in your ~/.gitconfig file. Using it will list all of your git aliases, in nearly the same format as they are in the ~/.gitconfig file. To use it, type:

$ git alias
loga = log --graph --decorate --name-status --all
alias = ! git config --get-regexp ^alias\. | sed -e s/^alias\.// -e s/\ /\ =\ /

The following considerations apply:

  • To prevent the alias alias from getting listed as above, append | grep -v ^'alias ' just before the closing double-quote. I don't recommend this so users don't forget that the the command alias is but an alias and is not a feature of git.

  • To sort the listed aliases, append | sort just before the closing double-quote. Alternatively, you can keep the aliases in ~/.gitconfig sorted.

  • To add the alias as a system-wide alias, replace --global (for current user) with --system (for all users). This typically goes in the /etc/gitconfig file.

Asclepius
  • 57,944
  • 17
  • 167
  • 143
  • 4
    I like this one because it gets rid of the `alias.` at the beginning of each line – Brian J Jun 16 '14 at 14:34
  • 3
    Not sure why, but this answer does not work for me. I keep getting `fatal: bad config`. Git-extra's solution does work for me though: https://github.com/tj/git-extras/blob/master/bin/git-alias – Ashitaka Jan 02 '15 at 19:05
  • 1
    @Ashitaka, try a limited version, e.g. `git config --global alias.alias "! git config --get-regexp ^alias\."`. Alternatively, ensure with `git version` that you've a current version of git. – Asclepius Jan 02 '15 at 19:34
  • This is really great work and puts it all together in an extremely usable manner! – UpAndAdam Jan 27 '16 at 17:28
  • I believe you can get rid of the "! git" part, which basically undoes each other. See the closing section of [Git Aliases](https://git-scm.com/book/en/v2/Git-Basics-Git-Aliases) – Daniel Stevens Jul 01 '18 at 06:05
  • This is a great answer, but not putting a pipe to `sort` before piping to `sed` is a rough way to go if you have more than a few aliases. Add a `sort` and this is a perfect answer. – mattmc3 Mar 18 '19 at 20:42
  • This shows very good effort, and works as intended. Best answer. – Erkka Mutanen Oct 06 '21 at 08:08
  • 2
    Only one expression needed: `sed -e 's/\\(^alias\\)\\./\\1 = /'`. I like to throw in some color: `sed -e 's/^alias\\.\\([^ ]*\\)/\\x1B[33m\\1\\x1B[0m =/'` – caduceus Feb 23 '22 at 07:12
  • Until today this is one of the most frequently used commands I use in my everyday workflow. This answer saved me an endless amount of time within the last years. Thank you! – Froxx Mar 10 '23 at 22:39
166

I created a git alias called (strangely enough) alias for exactly this purpose... handy from time to time if you use aliasing enough...

$ git config --global alias.alias "config --get-regexp ^alias\."

Note, the regex makes sure the line starts with alias..

gitaarik
  • 42,736
  • 12
  • 98
  • 105
johnny
  • 4,024
  • 2
  • 24
  • 38
  • I have added an [answer](http://stackoverflow.com/a/22183573/832230) which builds slightly upon this answer. – Asclepius Mar 04 '14 at 21:38
  • 2
    I suggest `--system` instead of `--global` as something like this is more useful at the system level, not a user level. – ADTC Sep 11 '14 at 03:39
  • 2
    And if you want to add it directly to your gitconfig it must look like this: `alias = config --get-regexp ^alias\\.`. – marczych May 11 '16 at 19:18
  • How about `git config --global alias.alias "!git config --get-regexp ^alias\. | grep -Po '(?<=alias\.)\S*' | sort"` – Keith Robertson Mar 19 '19 at 21:52
105

Another alternative (purely something I find easy to remember):

git config --list | grep alias

Rimian
  • 36,864
  • 16
  • 117
  • 117
  • 13
    Speaking of easy to remember, you might as well [create the `alias` alias](http://stackoverflow.com/a/22183573/832230) once and then forget you even created it. – Asclepius Mar 04 '14 at 21:41
  • 3
    You can use `-l` as a convenient shortcut for `--list` but I like the idea of creating an alias to list the aliases. – ADTC Sep 11 '14 at 03:44
  • 1
    Good solution, but better using grep with a regex to yield lines starting with alias in case some configurations somehow contains keyword alias: `git config --list | grep -E '^alias'` – MasterMind Feb 02 '18 at 10:19
30

The following works under Linux, MacOSX and Windows (with msysgit).

Use git la to show aliases in .gitconfig

Did I hear 'bash scripting'? ;)

About the 'not needed' part in a comment above, I basically created a man page like overview for my aliases. Why all the fuss? Isn't that complete overkill?

Read on...

I have set the commands like this in my .gitconfig, separated like TAB=TAB:

[alias]
        alias1            =            foo -x -y --z-option
        alias2            =            bar -y --z-option --set-something

and simply defined another alias to grep the TAB= part of the defined aliases. (All other options don't have tabs before and after the '=' in their definition, just spaces.)

Comments not appended to an alias also have a TAB===== appended, so they are shown after grepping.

For better viewing I am piping the grep output into less, like this:

basic version: (black/white)

  #.gitconfig
  [alias]
        # use 'git h <command>' for help, use 'git la' to list aliases  =====
        h     =     help #... <git-command-in-question>
        la    =     "!grep '\t=' ~/.gitconfig | less" 

The '\t=' part matches TAB=.

To have an even better overview of what aliases I have, and since I use the bash console, I colored the output with terminal colors:

  • all '=' are printed in red
  • all '#' are printed in green

advanced version: (colored)

       la      =       "!grep '\t=' ~/.gitconfig | sed -e 's/=/^[[0;31m=^[[0m/g' | sed -e 's/#.*/^[[0;32m&^[[0m/g' | less -R"

Basically the same as above, just sed usage is added to get the color codes into the output.

The -R flag of less is needed to get the colors shown in less.

(I recently found out, that long commands with a scrollbar under their window are not shown correctly on mobile devices: They text is cut off and the scrollbar is simply missing. That might be the case with the last code snippet here, keep that in mind when looking at code snippets here while on the go.)


Why get such magic to work?

I have a like half a mile of aliases, tailored to my needs.
Also some of them change over time, so after all the best idea to have an up-to-date list at hand is parsing the .gitconfig.

A ****short**** excerpt from my .gitconfig aliases:

    #  choose       =====
    a       =       add #...
    aa      =       add .
    ai      =       add -i
    #  unchoose     =====
    rm      =       rm -r #... unversion and delete
    rmc     =       rm -r --cached #... unversion, but leave in working copy
    #  do   =====
    c       =       commit -m #...
    fc      =       commit -am "fastcommit"
    ca      =       commit -am #...
    mc      =       commit # think 'message-commit'
    mca     =       commit -a
    cam     =       commit --amend -C HEAD # update last commit
    #  undo =====
    r       =       reset --hard HEAD
    rv      =       revert HEAD

In my linux or mac workstations also further aliases exist in the .bashrc's, sort of like:

#.bashrc
alias g="git"
alias gh="git h"
alias gla="git la"
function gc { git c "$*" } # this is handy, just type 'gc this is my commitmessage' at prompt

That way no need to type git help submodule, no need for git h submodule, just gh submodule is all that is needed to get the help. It is just some characters, but how often do you type them?

I use all of the following, of course only with shortcuts...

  • add
  • commit
  • commit --amend
  • reset --hard HEAD
  • push
  • fetch
  • rebase
  • checkout
  • branch
  • show-branch (in a lot of variations)
  • shortlog
  • reflog
  • diff (in variations)
  • log (in a lot of variations)
  • status
  • show
  • notes
  • ...

This was just from the top of my head.

I often have to use git without a gui, since a lot of the git commands are not implemented properly in any of the graphical frontends. But everytime I put them to use, it is mostly in the same manner.

On the 'not implemented' part mentioned in the last paragraph:
I have yet to find something that compares to this in a GUI:
sba = show-branch --color=always -a --more=10 --no-name - show all local and remote branches as well as the commits they have within them
ccm = "!git reset --soft HEAD~ && git commit" - change last commit message

From a point of view that is more simple:
How often do you type git add . or git commit -am "..."? Not counting even the rest...
Getting things to work like git aa or git ca "..." in windows,
or with bash aliases gaa/g aa or gca "..."/g ca "..." in linux and on mac's...

For my needs it seemed a smart thing to do, to tailor git commands like this...
... and for easier use I just helped myself for lesser used commands, so i dont have to consult the man pages everytime. Commands are predefined and looking them up is as easy as possible.

I mean, we are programmers after all? Getting things to work like we need them is our job.

Here is an additional screenshot, this works in Windows:

script working with cmd.exe

BONUS: If you are on linux or mac, colorized man pages can help you quite a bit:

colorized man pages

Community
  • 1
  • 1
sjas
  • 18,644
  • 14
  • 87
  • 92
  • 1
    I can not get this to work with Windows. The outputs are blank for e.g. `la = "!grep '\t=' ~/.gitconfig | less" ` – chwi Oct 29 '12 at 13:10
  • 1
    @Wilhelmsen : Did you maybe copy&paste things from the listing above? Do you really have a `TAB` preceeding every `=`? With spaces it will not work. I had spaces in my windows `.gitconfig` myself, once I replaced them with a single tabstop, cmd.exe behaves like expected. – sjas Dec 27 '12 at 20:49
  • 4
    overengineering – Ed_ Jun 03 '19 at 19:45
  • depends on how often you use something – sjas Jun 04 '19 at 17:27
19

As other answers mentioned, git config -l lists all your configuration details from your config file. Here's a partial example of that output for my configuration:

...
alias.force=push -f
alias.wd=diff --color-words
alias.shove=push -f
alias.gitignore=!git ls-files -i --exclude-from=.gitignore | xargs git rm --cached
alias.branches=!git remote show origin | grep \w*\s*(new^|tracked) -E
core.repositoryformatversion=0
core.filemode=false
core.bare=false
...

So we can grep out the alias lines, using git config -l | grep alias:

alias.force=push -f
alias.wd=diff --color-words
alias.shove=push -f
alias.gitignore=!git ls-files -i --exclude-from=.gitignore | xargs git rm --cached
alias.branches=!git remote show origin | grep \w*\s*(new^|tracked) -E

We can make this prettier by just cutting out the alias. part of each line, leaving us with this command:

git config -l | grep alias | cut -c 7-

Which prints:

force=push -f
wd=diff --color-words
shove=push -f
gitignore=!git ls-files -i --exclude-from=.gitignore | xargs git rm --cached
branches=!git remote show origin | grep \w*\s*(new^|tracked) -E

Lastly, don't forget to add this as an alias:

git config --global alias.la "!git config -l | grep alias | cut -c 7-"

Enjoy!

Anubian Noob
  • 13,426
  • 6
  • 53
  • 75
17

Using git var and filtering only those that start with alias:

git var -l | grep -e "^alias"
mkobit
  • 43,979
  • 12
  • 156
  • 150
17

I mentioned in June 2018 with "overview list - most used git commands" the Git 2.18 "use --list-cmds=alias (commit 3301d36)", that carej reports in his answer.

 git --list-cmds=alias

In addition of that or of git config --get-regexp alias, you can combine its output with git help, whose output will change with Git 2.14.x/2.15:

"git help co" now says "co is aliased to ...", not "git co is".

See commit b3a8076 (12 Sep 2017) by Kaartic Sivaraam (sivaraam).
(Merged by Junio C Hamano -- gitster -- in commit 5079cc8, 25 Sep 2017)

help: change a message to be more precise

When the user tries to use '--help' option on an aliased command information about the alias is printed as shown below:

$ git co --help
`git co' is aliased to `checkout'

This doesn't seem correct as the user has aliased only 'co' and not 'git co'.
This might even be incorrect in cases in which the user has used an alias like 'tgit'.

$ tgit co --help
`git co' is aliased to `checkout'
Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
17

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.)


Explanation

  1. !git config --get-regexp ^alias\\. prints all lines from git config that start with alias.
  2. sed -e s/^alias.// removes alias. from the line
  3. sed -e s/\\ /\\ $(printf \"\\043\")--\\>\\ / replaces the first occurrence of a space with \\ $(printf \"\\043\")--\\> (which evaluates to #-->).
  4. 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.
  5. 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.

Thomas
  • 2,155
  • 16
  • 22
17

Both Works Well

1 - Using Get Regex

$ git config --get-regexp alias

2 - Using list

$ git config --list | grep alias
Dificilcoder
  • 449
  • 5
  • 11
13

for windows:

git config --list | findstr "alias"
176coding
  • 2,933
  • 4
  • 17
  • 18
11

Search or show all aliases

Add to your .gitconfig under [alias]:

aliases = !git config --list | grep ^alias\\. | cut -c 7- | grep -Ei --color \"$1\" "#"

Then you can do

  • git aliases - show ALL aliases
  • git aliases commit - only aliases containing "commit"
Community
  • 1
  • 1
Tom Hale
  • 40,825
  • 36
  • 187
  • 242
6

Just adding this because it's so simple and I didn't see it in previous answers (sorry if I missed it).

git help -a

You'll have to scroll to the bottom (use > as ma11hew28 pointed out) to see the list, e.g.:

Command aliases
   restore-deleted      !git restore $(git ls-files -d)

If you forget even this switch, a simple git help will help you remember:

'git help -a' and 'git help -g' list available subcommands and some concept guides. See 'git help ' or 'git help ' to read about a specific subcommand or concept.

Nagev
  • 10,835
  • 4
  • 58
  • 69
  • 3
    `git help -a` displays in `less` for me, so I can type `G` or `>` to jump to the last line. Or you can just run `git help -a | sed '1,/aliases$/d'`. I added that command as an alias in my global Git configuration file by running `git config --global alias.alias "\!git help -a | sed '1,/aliases$/d'"`. Now I can just run `git alias` to list my Git aliases. – ma11hew28 Sep 02 '22 at 21:38
  • @ma11hew28 Pretty good solution! – projetmbc Apr 30 '23 at 22:14
4

As of git 2.18 you can use git --list-cmds=alias

carej
  • 596
  • 1
  • 6
  • 18
4

this simple solution worked well for me

  1. create an alias for listing aliases :) git config --global alias.aliases "config --get-regexp '^alias\.'"
  2. execute it git aliases to list all of our other aliases
Éric F
  • 63
  • 7
3

I like @Thomas's answer, and I do some modifications.

features:

  • add color
  • and input parameter: to let the user choose command (from git config --get-regexp ^.)
  • add filter
# .gitconfig

[alias]
    show-cmd = "!f() { \
        sep="㊣" ;\
        name=${1:-alias};\
        echo -n -e '\\033[48;2;255;255;01m' ;\
        echo -n -e '\\033[38;2;255;0;01m' ;\
        echo "$name"; \
        echo -n -e '\\033[m' ;\
        git config --get-regexp ^$name\\..*$2+ | \
        cut -c 1-40 | \
        sed -e s/^$name.// \
        -e s/\\ /\\ $(printf $sep)--\\>\\ / | \
        column -t -s $(printf $sep) | \
        sort -k 1 ;\
    }; f"

USAGE

  1. git show-cmd list alias
  2. git show-cmd "" st list alias, and it should contain the string st
  3. git show-cmd i18n show i18n setting
  4. git show-cmd core editor show core setting, and it should contain editor

DEMO

enter image description here

It's working fine on windows too

Explanation

  • you can write the long script on .gitconfig use the syntax as below:

    [alias]
        your-cmd = "!f() { \
            \
        }; f"
    
  • name=${1:-alias} same as name = $1 if $1 else -alias

  • echo -n -e (see more echo)

    • -n = Do not output a trailing newline.
    • -e Enable interpretation of the following backslash-escaped
  • '\\033[38;2;255;0;01m' (see more SGR parameters)

    • \\033[48; : 48 means background color.
    • \\033[38;2;255;0;0m : 38 means fore color. 255;0;0 = Red
  • cut -c 1-40 To avoid your command is too long, so take 40 char only.

  • sed -e 's/be_replace_string/new_string/' replace string to new string. (if you want to put the special-char(such as space, > ...) should add \\ as the prefix.

  • column -t -s $(printf $sep) formats all lines into an evenly spaced column table.

  • sort -k 1 sorts all lines based on the value in the first column

Carson
  • 6,105
  • 2
  • 37
  • 45
2

There is a built-in function... try

$ __git_aliases

lists all the aliases :)

vigo
  • 298
  • 3
  • 8
  • 3
    Can you show a command line example of how to use this, along with sample output? – Asclepius Aug 27 '14 at 20:06
  • Built in to what? I can't find anything of this sort in msysgit. Where exactly did you find this? – ADTC Sep 11 '14 at 03:41
  • 2
    Neither calling this directly from terminal or as an argument to git produces any output of value. What exactly is this built in to? – agreeingly-ascyphous Jan 14 '15 at 12:44
  • 4
    Worked for me in git bash. $ __git_aliases returns a list of aliases, although it doesn't show what they are aliased to. – jaypb Jan 21 '15 at 18:30
  • @vigo yes. Git for Windows (aka msysgit). It does install the Git command line. In any case, `__git_aliases`, `$ __git_aliases`, `echo $__git_aliases` etc produced *nothing useful*. **ntlv** and myself are still waiting for the answer to "what exactly is this built in to?" and please expand the answer with a command line example of how to use this, with sample output, as **A-B-B** has asked. – ADTC Feb 02 '16 at 09:15
  • @ADTC so sorry, I have no experience on Windows :( – vigo Feb 20 '16 at 09:07
  • @vigo OK noted on that, but you can still expand the answer with a command line example (Linux terminal, or whatever) with sample output and expound on the "built-in" nature of the function, as requested. Thanks. – ADTC Feb 22 '16 at 08:56
  • `for i in $(git config --name-only --get-regexp "^alias\..*"); do echo "${i#alias.}"; done | xargs -n 1 git alias` – vigo Apr 06 '16 at 17:46
  • 1
    @ADTC the code line in this answer **is** a command line example. The `$ ` denotes the typical linux terminal prompt. Type the rest of this line into such a terminal and hit `ENTER` and out comes a list of your aliases. Works on both Linux and Windows(git bash), because it is _built-in_ to git. (It is probably a function that git uses internally to resolve aliases when they are used on the command line.) – Superole Jul 14 '17 at 12:32
2
  1. Open .gitconfig file (C:\Users\user.gitconfig) --Windows

  2. Under [alias] copy & paste the below code

    alias = !git config --list | grep ^alias\\. | cut -c 7- | grep -Ei --color \"$1\" "#"

  3. In terminal git alias -- Lists all aliases

  4. In terminal git alias commit -- Lists all aliases related to commit

  5. Get list of all aliases without remembering the code :)

Akashxolotl
  • 428
  • 5
  • 6
1

If you know the name of the alias, you can use the --help option to describe it. For example:

$ git sa --help
`git sa' is aliased to `stash'

$ git a --help
`git a' is aliased to `add'
Asclepius
  • 57,944
  • 17
  • 167
  • 143
cmcginty
  • 113,384
  • 42
  • 163
  • 163
1

Yet another git alias (called alias) that prints out git aliases: add the following to your gitconfig [alias] section:

[alias]
    # lists aliases matching a regular expression
    alias = "!f() { git config --get-regexp "^alias.${1}$" ; }; f"

Example usage, giving full alias name (matches alias name exactly: i.e., ^foobar$), and simply shows the value:

$ git alias st
alias.st status -s

$ git alias dif
alias.dif diff

Or, give regexp, which shows all matching aliases & values:

$ git alias 'dif.*'
alias.dif diff
alias.difs diff --staged
alias.difh diff HEAD
alias.difr diff @{u}
alias.difl diff --name-only

$ git alias '.*ing'
alias.incoming !git remote update -p; git log ..@{u}
alias.outgoing log @{u}..

Caveats: quote the regexp to prevent shell expansion as a glob, although it's not technically necessary if/when no files match the pattern. Also: any regexp is fine, except ^ (pattern start) and $ (pattern end) can't be used; they are implied. Assumes you're not using git-alias from git-extras.

Also, obviously your aliases will be different; these are just a few that I have configured. (Perhaps you'll find them useful, too.)

michael
  • 9,161
  • 2
  • 52
  • 49
1

You can create an alias to show all git alias on your machine. Run below code.

git config --global alias.alias "! git config --get-regexp ^alias\. | sed -e s/^alias\.// -e s/\ /\ =\ /"

then, simply run git alias.

VivekRajendran
  • 676
  • 1
  • 6
  • 21
0

Here my aliases for the community: git aliases and git get-alias

With git aliases you get the plain list of your git aliases. With git get-alias <alias-name> you get the alias content.

git config --global alias.aliases '!f() { git config --get-regexp "^alias\." | cut -d " " -f 1 | cut -d "." -f 2 ; }; f'

git config --global alias.get-alias '!f() { git config --get-regexp "^alias\." | grep $1 ; }; f'
Alessandro Argentieri
  • 2,901
  • 3
  • 32
  • 62
0
$ git alias -h

'alias' is aliased to '!git config --list | grep 'alias\.' | sed 
's/alias\.\([^=]*\)=\(.*\)/\1\  => \2/' | sort'
a        => !git add . && git status
aa       => !git add . && git add -u . && git status
ac       => !git add . && git commit
acm      => !git add . && git commit -m
iserdmi
  • 75
  • 1
  • 11
  • 1
    As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community May 17 '22 at 00:17
0

List global and local Git aliases using Bash. This will work even if Git is not installed.

$ cat ~/.gitconfig .git/config 2>/dev/null | sed -n '/alias/,/\[/p' | grep -v '^\['
        co = checkout
        br = branch
        ci = commit
        st = status

2>/dev/null - hides errors in case config files do not exist
sed -n '/alias/,/\[/p' - lists contents of alias section(s)
grep -v '^\[' - hides section markers (they begin with the left square bracket)

Bash alias for the same command

$ alias gita="cat ~/.gitconfig .git/config 2>/dev/null | sed -n '/alias/,/\[/p' | grep -v '^\['"

$ gita
        co = checkout
        br = branch
        ci = commit
        st = status
Dmitry
  • 354
  • 3
  • 6