User Tools

Site Tools


git_aliases

This is an old revision of the document!


Overview

Setting and listing aliases

Setting regular Git aliases

How to set a regular Git alias (note the need for quotes with multi-word values):

$ git config --global alias.a add
$ git config --global alias.cm commit
$ git config --global alias.co checkout
$ git config --global alias.b branch
$ git config --global alias.cb "checkout -b"

after which you can use Git commands like:

$ git a Makefile
$ git cm
$ git cb newbranch

Recursive Git aliases

You can also define Git aliases in terms of other Git aliases:

$ git config --global alias.bl blame
$ git config --global alias.bm 'bl Makefile"

after which you could run the equivalent of git blame Makefile with:

$ git bm

Aliases in the .gitconfig file

What ends up in your ~/.gitconfig file:

...
[alias]
        a = add
        cm = commit
        co = checkout
        b = blame
        cb = checkout -b
        bm = b Makefile
...        

How to unset Git aliases

$ git config --global --unset alias.blm

or just edit the .gitconfig file.

How to set a shell-style Git alias

$ git alias bu "!git rev-parse --abbrev-ref --symbolic-full-name "@{u}""
git_aliases.1550412938.txt.gz · Last modified: 2019/02/17 14:15 by rpjday