What are your favorite git aliases? I know this was somewhat discussed in other git question, I want to get a more specific/focused list of useful aliases...

Feel free to post additional ones for me to update here. It might be better to post one per answer so people get to vote on them independently...

So far:

##
# Abbreviations
git config --global alias.st status
git config --global alias.co checkout
git config --global alias.ci commit
git config --global alias.br branch

##
# Pimp-out log:
# From: http://www.jukie.net/bart/blog/pimping-out-git-log
git config --global alias.lg "log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative"

##
# Quickly Commit / Uncommit Work-In-Progress
# By David Gageot (http://gist.github.com/492227): 
git config --global alias.wip "git add -A; git ls-files --deleted -z | xargs -0 git rm; git commit -m \"wip\""
git config --global alias.unwip "git log -n 1 | grep -q -c wip && git reset HEAD~1"

## 
# commit + sign
git config --global alias.cs "commit -s"
link|improve this question
feedback

migrated from stackoverflow.com Jul 30 '10 at 1:08

This question came from our site for professional and enthusiast programmers.

closed as not a real question by Jeff Atwood Apr 26 '11 at 19:05

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. See the FAQ for guidance on how to improve it.

10 Answers

[alias]
  panic = !tar cvf ../git_panic.tar *
  co = checkout
  br = branch
  mav = !afplay -s 0 12 ~/Music/iTunes/iTunes\\ Music/Kenny\\ Loggins/Top\\ Gun/Danger\\ Zone.mp3 &\ngit rebase -i  
  lg = log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr)%Creset' --abbrev-commit --date=relative

usage:

git panic       :when you're a little worried that the world is coming to an end 
git mav HEAD~4  :to interactively rebase the last 4 commits and listen to DangerZone
git lg          :sweet branch visualization in the terminal
link|improve this answer
6  
Re: git panic, I find more comfort in changing that '*' to '.' in order to back up the '.git' folder also. – Nickolay Jan 16 '11 at 14:22
3  
I'm upvoting this answer SOLELY on the fact that Kenny Loggins' Danger Zone will be played during a rebase. I'm pretty sure I literally laughed out loud on that one. Brilliant. – program247365 Nov 1 '11 at 15:10
Danger Zone during rebasing is both fitting and hilarious. Note that you can grab the pid via $! and kill it after the rebase, so the music stops after the rebase finishes (if desired). – rjh Feb 28 at 22:45
feedback

I like the ones from David Gageot:

[alias]
  wip = !"git add -A; git ls-files --deleted -z | xargs -0 git rm; git commit -m \"wip\""
  unwip = !"git log -n 1 | grep -q -c wip && git reset HEAD~1"
  rb = !"git wip;git rebase -i origin/master;git unwip"
  pr = !"git fetch;git wip;git rebase --stat origin;git unwip;git heads"
  head = !"git log -n1"
  lost = !"git fsck | awk '/dangling commit/ {print $3}' | git show --format='SHA1: %C(yellow)%h%Creset %f' --stdin | awk '/SHA1/ {sub(\"SHA1: \", \"\"); print}'"
  heads = !"git log origin/master.. --format='%Cred%h%Creset;%C(yellow)%an%Creset;%H;%Cblue%f%Creset' | git name-rev --stdin --always --name-only | column -t -s';'"
  • The wip allows for a quick way to add all new and modified files to the index, while cleaning the index from the files removed from the working tree.
  • The unwip will restore the deleted files to the working tree!

A 'wip' "cleaning" facilites the rebase, because there won't be any conlfict due to an "unclean" working directory (not in sync with the index)

link|improve this answer
1  
+1 for "git lost" – Gabe Moothart Oct 12 '10 at 14:28
Presumably git stash now supercedes a lot of this wip stuff? – rjh Feb 28 at 22:45
feedback

I regularly use

fix = commit --amend -C HEAD

when I realize that I made a typo or forgot to include a change in my most recent commit. To use it, either git add the changes that should be added to the top commit and then run git fix, or run git fix with additional arguments that specify what should be included, for example:

git fix FILE1 FILE2     # Add changes to FILE1 and FILE2 to top commit
git fix -a              # Add all changes in working copy to top commit
link|improve this answer
feedback

I basically just abbreviate the command itself so I don't have to type the full thing out.

[alias]
    st = status
    ci = commit
    cia = commit --amend
    co = checkout
    br = branch
    sb = show-branch
    cp = cherry-pick
    staged = diff --cached
    rb = rebase
    rbc = rebase --continue
    rbs = rebase --skip
    rl = reflog
    rs = remote show
    rt = remote
    ru = remote update
    rp = remote prune
    sm = submodule
link|improve this answer
feedback

Sometimes it is useful to detach the HEAD from the current branch, for example when doing a test merge:

detach = checkout HEAD^0
link|improve this answer
feedback

Sadly:

cvs = !git cvsimport -k -a
cvsx = cvsexportcommit -u -p 
cvsxh = cvsexportcommit -u -p -c HEAD
link|improve this answer
I won't add them to the main list, so not to shame you, but you do have my sincere condolences ;) JK, I'm just trying to keep it more git-core / workflow oriented – damageboy Jul 29 '10 at 14:08
feedback

I always sign my commits, got tired of forgetting to type -s

cs = commit -s
link|improve this answer
feedback

I use this one a lot:

gitdc = "git diff --color"
link|improve this answer
11  
why not just do this? [color] ui = auto or just turn on color for diff using something similar – xenoterracide Jul 28 '10 at 14:00
feedback

Some commands I use:

This is quite a handy command. It does pretty much everything you want submodules for. However, it works only since git 1.7.1:

sub = submodule update --init --recursive 

You surely have your favorite way to display graph of commits (see git lg described in the question). But sometimes you don't want to open pager. You might want ot add an alias for that:

last = !git --no-pager your-command-to-print-graph -20
link|improve this answer
feedback

Simple aliases, mostly for easier staging/comparing/unstaging:

add = add -v
st = status
staged = diff --staged
unstage = reset HEAD
diff-all = diff HEAD
diff-stat = diff -b --stat

Log commands:

log-graph = log --all --graph --decorate
log-refs = log --all --graph --decorate --oneline --simplify-by-decoration --no-merges
log-timeline = log --format='%h %an %ar - %s'
log-local = log --oneline origin..HEAD
log-fetched = log --oneline HEAD..origin/master
link|improve this answer
feedback

Not the answer you're looking for? Browse other questions tagged or ask your own question.