Git snippets

Ryan Kennedy


Here’s what I like to keep in my Git config:

~/.gitconfig
[color]
  ui = true

[alias]
  # Useful for pushing branches with long names.
  # $ git push origin $(git this)
  this = rev-parse --abbrev-ref HEAD
  puot = !git push -u origin $(git this)
  
  # Useful for when I've been switching branches, and can't remember
  # which one I was working on.
  # Run `git recent | head` unless you enjoy information overload.
  recent = branch --sort=-committerdate

  # I use these two daily to clean up pull requests.
  ri = rebase -i --autosquash
  fix = commit --fixup

  # Less oft-used but still useful.
  mri = rebase -i
  squ = commit --squash

  # Starting "from scratch" with a node.js project.
  rmod = !rm -rf node_modules package-lock.json

  # In case permissions get messed up.
  permission-reset = !git diff -p -R | grep -E \"^(diff|(old|new) mode)\" | git apply

  # Quicker to type
  bbpr = bb-create-pull-request
  
  # Quick branch manipulation
  cono = checkout --no-track
  cod = checkout origin/develop -b
  comaster = checkout --no-track origin/master -b
  mod=merge origin/develop
  mom=merge origin/master
  moth="!git merge origin/$(git this)"
  moff="!git moth --ff-only"
  mobble="!git moth --no-ff"

  # Force push, to heck with consequences
  yolo="!git puot -f"
  # Force push *and* don't run tests
  yolowhoa="!git yolo --no-verify"


# Allow you to compare "ours" and "theirs" against the previous version
# when working on a merge conflict.
[merge]
  conflictstyle=diff3

[difftool "sourcetree"]
  cmd = opendiff \"$LOCAL\" \"$REMOTE\"
  path =
[mergetool "sourcetree"]
  cmd = /Applications/SourceTree.app/Contents/Resources/opendiff-w.sh \"$LOCAL\" \"$REMOTE\" -ancestor \"$BASE\" -merge \"$MERGED\"
  trustExitCode = true