Some Git aliases.

Xavier suggested I blog my Git aliases.

[alias]
	ci = commit -v
	prune-all = !git remote | xargs -n 1 git remote prune
	record = !git add -p && git ci
	amend-record = !git add -p && git ci --amend
	stoat = !toilet -f future STOATS
	update-master = !git checkout master && git pull -r
	lol = log --graph --decorate --pretty=oneline --abbrev-commit
	lola = log --graph --decorate --pretty=oneline --abbrev-commit --all

Mostly ((No, I don’t remember why I added git stoat either.)) self-explanatory.

git ci
Shorter than git commit, and -v shows you what you’re about to commit.
git prune-all
From the Git wiki.
git record; git amend-record
I started using these as a Darcs refugee, but they’re also a good way to avoid doing git add -p && git commit -a through overly-active muscle memory. I could probably simplify them to use git commit -p.
git lol; git lola
…come from Conrad Parker.

What’re your favourites?

9 thoughts on “Some Git aliases.”

  1. I’ve been using lol and lola for a while now, and I just couldn’t do without them.

    I’m also always running in the “git add -p; git commit -a” trap, so I’ll take a serious look at that record alias. 🙂

    Thanks!

  2. a bunch of things I’ve stolen around GitHub and the kernel mailing list:

           # patch: Generate the patch of a commit
            # Usage: git patch 
            patch = log -p --no-walk
            # me: Show all the commits I have done to the kernel
            me = log --tags --source --oneline --author=ebassi@linux.intel.com
            # author: Show all the commits a specificed author has done to the kernel
            # Usage: git author 
            author = "!sh -c 'git log --tags --source --oneline --author=\"$1\"' -"
            # Usage: git whois 
            whois = "!sh -c 'git log -i -1 --pretty=\"format:%an \n\" --author=\"$1\"' -"
            # Usage: git whatis 
            whatis = show -s --pretty='tformat:%h (%s, %ad)' --date=short
            # fixup: Update the previous commit using the same commit message
            fixup = !git add -p && git commit --amend -C HEAD
    

    fixup is mostly because I like to commit immediately and then do stuff like whitespace cleaning of the newly committed code, or fixing typos in the docs, or adding tests, before pushing.

  3. At work, we use git a lot like most people use svn as a central code repository. As a result, there is a policy in place to prevent merge commits and enforced with hooks. In svn-land, “svn up” is vaguely equivalent to “git pull –rebase” so I’ve got an alias named “git up” which does just that. I also added an alias named “down” that is just “push”. The workflow is when a merge commit gets rejected, I’ve simply got to to:

    git up && git down

    It makes me laugh every single time.

    A few others:
    wdiff = diff –color-words
    wshow = show –color-words
    egrep = grep -E
    createpatch = format-patch -M -C –patience –full-index
    diffstat = diff –stat
    staged = diff –cached
    unstaged = diff

  4. cp = cherry-pick
    ci = commit
    co = checkout
    st = status
    stu = status –untracked=no
    br = branch
    up = pull –rebase

  5. So, you can make autosquash default to yes, which is nice, so my ‘rbi’ alias means I just type ‘git rbi’ compulsively to automatically clean up history.

    These are my shell functions:

    gd() {
        PAGER="vim -" git diff $*
    }
    gs() {
        PAGER="vim -" git show $*
    }
    gc() { # show the file $2 from the ref $1
        PAGER="vim -" git cat-file -p $(git ls-tree $1 $2 | awk '{ print $3; }')
    }

    And my aliases:

            rbi = rebase -i
            rbs = rebase --skip
            rba = rebase --abort
            rbc = rebase --continue
            dac = describe --all --contains # find tag/branch for commit
            whatis = show -s --pretty='tformat:%h (%s, %ad)' --date=short
            addrb = filter-branch --msg-filter ~/bin/r-b # adds reviewed-by tag in conjunction with the following script

    and ~/bin/r-b:

    #!/bin/sh
    
    if [ -n "$GIT_AUTHOR_NAME" ] && [ -n "$GIT_AUTHOR_EMAIL" ]; then
        MY_ID="$GIT_AUTHOR_NAME "
    elif [ -n "$(git config --get user.name)" ] &&
         [ -n "$(git config --get user.email)" ]; then
        MY_ID="$(git config --get user.name) "
    fi
    
    ARGS=$@
    if [ -z "$ARGS" ] && [ -n "$MY_ID" ]; then
        ARGS="Reviewed-by: $MY_ID"
    elif [ "x$ARGS" = "whot" ]; then
        ARGS="Reviewed-by: Peter Hutterer "
    fi
    
    # Build the awk command line, reverse param orders:
    cmd=
    for i in "$ARGS"; do
      cmd="print \"$i\"; $cmd"
    done
    
    # Insert lines after the first/last empty line:
    cat | awk \
       "BEGIN {
            needs_blank=1
        };
        /Signed-off-by/ || /Reviewed-by/ || /Tested-by/ || /Reported-by/ {
            needs_blank=0
        };
        {
            print
        };
        END {
            if (needs_blank) {
                print \"\"
            }
            $cmd
        };"

    [Edited to add pre tags.]

  6. @Emmanuele: What’s the difference between `git log -p –no-walk` and `git show`?

Comments are closed.