Gitconfig

Ease your git use by using a gitconfig

Git is a great versioning tool. I use it in all my day-to-day activities and non-work projects. Basically anything I write, is versioned via git.

The following snippet can be saved in ~/.gitconfig and it will automatically be picked up. Parts of it are related to Atlassian’s gitflow

[user]
  email = <email>
  name = <name>
  signingkey = <key>
[alias]
  bw = blame -w -M
  c = commit
  b = rev-parse --abbrev-ref HEAD
  commend = commit --amend --no-edit
  cc = commit --all --amend --no-edit
  ca = commit --all
  co = checkout
  cb = "!f() { git checkout `git log --until=\"$*\" -1 --format=%h`; } ; f"
  s = status --short
  d = diff
  dc = diff --cached --word-diff=color
  dw = diff --word-diff=color
  l = log
  a = add
  af = add -f
  au = add -u # stages modified and deleted, without new
  p = push
  pf = push -f # force push, useful after using rebase
  ss = show -1 --format=%B--stat
  sw = show -1 --format=%B--stat --word-diff=color
  whatis = show -s --pretty='tformat:%h (%s, %ad)' --date=short
  lg = log --graph --pretty=format:'%Cred%h%Creset %C(yellow)%an%d%Creset %s [%N] %Cgreen(%ar)%Creset' --date=relative
  lgd = log --graph --pretty=format:'%Cred%h%Creset %C(yellow)%an%d%Creset %s [%N] %Cgreen(%ar)%Creset' --date=default
  lgm = log --graph --pretty=format:'%Cred%h%Creset %C(yellow)%an%d%Creset %s [%N] %Cgreen(%ar)%Creset' --date=relative --author=<email>
  abbr = "!sh -c 'git rev-list --all | grep ^$1 | while read commit; do git --no-pager log -n1 --pretty=format:\"%H %ci %an %s%n\" $commit; done' -"
  please = push --force-with-lease
  cis = commit -S # sign commits
  gw = whatchanged
[color]
  ui = auto
[branch]
  autosetuprebase = remote
[push]
  default = simple
[fetch]
  prune = true
[filter "lfs"]
  smudge = git-lfs smudge -- %f
  process = git-lfs filter-process
  required = true
  clean = git-lfs clean -- %f

Next, run both:

$ sed -i -e 's:<name>:'"Username"':g' .gitignore
$ sed -i -e 's:<email>:'"[email protected]"':g' .gitignore

replacing Username and [email protected] with your own credentials.


See also