From my .gitconfig.

    alias = config --get-regexp '^alias.*' # list available aliases
    # add and commit
    a = add
    aa = add --all
    ac = !git add . && git commit -am
    ap = add -p
    c = commit --verbose
    ca = commit -a --verbose
    cm = commit -m
    cam = commit -a -m
    m = commit --amend --verbose
    uncommit = reset --soft HEAD~1
    # branching
    ba = branch -a
    bd = branch -d
    bD = branch -D
    branches = branch --all
    branchrename = branch --move
    branchesdiffed = !git branch | grep -i "indiff"
    branchesundiffed = !git branch | grep -v -i "indiff"
    cleanmerged = !git branch --merged | grep -v \"\\*\" | xargs -n 1 git branch -d # remove merged branches
    co = checkout
    cob = checkout -b
    wipelocal = checkout .
    # diff
    d = diff
    ds = diff --stat
    dc = diff --cached
    f = fetch -p
    # remote
    p = push
    pr = pull --rebase
    pushitgood = push -u origin --all
    rao = remote add origin
    # rebase
    rb = rebase
    rba = rebase --abort
    rbc = rebase --continue
    rbs = rebase --skip
    # log
    st = status -sb
    plog = log --graph --pretty='format:%C(red)%d%C(reset) %C(yellow)%h%C(reset) %ar %C(green)%aN%C(reset) %s'
    tlog = log --stat --since='1 Day Ago' --graph --pretty=oneline --abbrev-commit --date=relative
    lg = log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit
    out = log --pretty=oneline --abbrev-commit --graph @{u}..
    in = !git fetch && git log --pretty=oneline --abbrev-commit --graph ..@{u}
    rank = shortlog -sn --no-merges
    winning = shortlog --summary --numbered --email
    totalcommits = !git log --all --pretty=oneline | wc -l
    commitslastmonth = !git log --author=\"`git config`\" --before={`date "+%Y-%m-01"`} --after={`date --date=\"$(date +%Y-%m-1) -1 month\" \"+%Y-%m-01\"`} --reverse --pretty=format:\"%cd %h  %s\" --date=short
    commitsthismonth = !git log --author=\"`git config`\" --before=now --after={`date "+%Y-%m-1"`} --reverse --pretty=format:\"%cd %h  %s\" --date=short
    commitstoday = !git log --author=\"`git config`\" --since=\"6am\"
    rank = shortlog -sn --no-merges


Embeds another Git repo within a Git repo. One handy use case is relatively referencing some common source, which is managed independently in its own Git repo. The submodule can be pinned to a particular branch by creating a .gitmodules file.

[submodule "common"]
    path = common
    url =
    branch = master

In each branch of the parent repo (the one that includes the submodule/s), you could commit slightly different versions of the .gitmodules so that branch of the submodule lines up. For example, you may want the develop branch of the parent repo, to use the develop branch of the submodule. However when in the master branch of the parent repo, you’d like the master branch of the submodule to be used.

Detached Head

Every now and then I end up with a detached head. WTF is a detached head again? It happens when you checkout a specific commit, instead of a branch. The HEAD pointer will stick to the specific commit, and no longer automatically point to the latest commit in the working branch. If you don’t realise the HEAD is detached, and get to work and make a bunch of changes, these changes can easily get lost as the correct commit/branch accounting is thrown out.

My favourite remedial action, is to stash the changes, then properly chechout the branch (not a commit!), pop the stash, stage and commit.