Git Tip: My Git Configuration (.gitconfig)

These are the things in my .gitconfig that help me the most. From avoiding those annoying pull commits, to key saving aliases.

[branch]
  # Avoid merge commits the result from git pull
  autosetuprebase = always
  autosetupmerge = always
  # Don’t fast forward commits during a merge
  mergeoptions = --no-ff

[fetch]
  # Before fetching, remove any remote-tracking references that no longer exist on the remote.
  prune = true

[merge]
  # Don’t fast forward commits during a merge
  ff = false

[mergetool]
  # Don’t prompt before each invocation of the merge resolution program.
  prompt = false

[alias]
  # save some key strokes
  co = checkout
  cp = cherry-pick

  # remove branches that are not present in remote
  klean = !git branch -vv | grep ': gone]' | awk '{print $1}' | xargs git branch -d

  # remove branches that are not present in remote even if they have not been merged into master
  kleanD = !git branch -vv | grep ': gone]' | awk '{print $1}' | xargs git branch -D

  # pull and push - if you commit on a branch and can't push because the remote is ahead, this will do the pull and push
  pap = !git pull --rebase && git push

  # fetch remote, prune, and pull in one command
  update = !git fetch --all --prune && git pull --rebase

  # update misspell
  udpate = !git fetch --all --prune && git pull --rebase