Last Updated: February 25, 2016
·
1.284K
· aaronjensen

Disable Guard while running `git checkout`

I like guard quite a bit for running various things including my tests and livereload.

What I don't like is when I do git checkout a branch and guard goes nutso restarting everything and running all sorts of tests.

To get around that I have a git co alias that will pause guard, checkout the branch and then unpause guard.

First add to your .bashrc:

function pause_guard {
  ps ax | grep -w bin/[g]uard | awk '{print $1}' | xargs kill -USR1
}

function unpause_guard {
  ps ax | grep -w bin/[g]uard | awk '{print $1}' | xargs kill -USR2
}

# Autocomplete for my "git co"
function _git_co {
  _git_checkout $*
}

Then add the alias to your .gitconfig:

[alias]
  co = "!bash -c 'pause_guard' ; git checkout $* ; bash -c 'unpause_guard'"

Now when you run git co branchname guard will be paused while the checkout is happening. If you want to force guard to reload afterwards, just go to guard and hit r<enter>

For more fun .gitconfig aliases check out my dotfiles.