List Git aliases

后端 未结 16 1992
暖寄归人
暖寄归人 2020-12-02 03:43

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

16条回答
  •  借酒劲吻你
    2020-12-02 03:53

    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.

提交回复
热议问题