Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
git_aliases [2018/06/04 11:12] – created rpjdaygit_aliases [2019/02/25 13:15] (current) – [How to set a shell-style Git alias] rpjday
Line 1: Line 1:
 ===== Overview ===== ===== Overview =====
  
-Proper definition and usage of Git aliases. For now, [[https://gist.github.com/pksunkara/988716|here's a good start]].+Proper definition and usage of Git aliases. 
 + 
 +Links: 
 + 
 +  * [[https://stackoverflow.com/questions/7066325/list-git-aliases/22183573#22183573|https://stackoverflow.com/questions/7066325/list-git-aliases/22183573#22183573]] 
 +  * [[https://gist.github.com/pksunkara/988716|https://gist.github.com/pksunkara/988716]] 
 + 
 +===== Setting and listing aliases ===== 
 + 
 +==== Setting regular Git aliases ==== 
 + 
 +How to set a //regular// Git alias (note the need for quotes with multi-word values): 
 + 
 +<code> 
 +$ 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" 
 +</code> 
 + 
 +after which you can use Git commands like: 
 + 
 +<code> 
 +$ git a Makefile 
 +$ git cm 
 +$ git cb newbranch 
 +</code> 
 + 
 +==== Recursive Git aliases ==== 
 + 
 +You can also define Git aliases in terms of other Git aliases: 
 + 
 +<code> 
 +$ git config --global alias.bl blame 
 +$ git config --global alias.bm 'bl Makefile" 
 +</code> 
 + 
 +after which you could run the equivalent of ''git blame Makefile'' with: 
 + 
 +<code> 
 +$ git bm 
 +</code> 
 +==== Aliases in the .gitconfig file ==== 
 + 
 +What ends up in your ''~/.gitconfig'' file: 
 + 
 +<code> 
 +... 
 +[alias] 
 +        a = add 
 +        cm = commit 
 +        co = checkout 
 +        b = blame 
 +        cb = checkout -b 
 +        bm = b Makefile 
 +...         
 +</code> 
 + 
 +===== How to unset Git aliases ===== 
 + 
 +<code> 
 +$ git config --global --unset alias.blm 
 +</code> 
 + 
 +or just edit the ''.gitconfig'' file. 
 +===== How to set a shell-style Git alias ===== 
 + 
 +<code> 
 +$ git alias bu "!git rev-parse --abbrev-ref --symbolic-full-name "@{u}"" 
 +</code> 
 + 
 +The shell command being run does not have to be ''git''.
  • git_aliases.1528110769.txt.gz
  • Last modified: 2018/06/04 11:12
  • by rpjday