Last Updated: February 25, 2016
· dcadenas

Efficient pattern search for multiple local git repos

This is very useful to use your own code as reference.

  1. Store all your local git repos in ~/code. You can change this but be sure to update point 3 accordingly.
  2. Install parallel. In macosx: brew install parallel
  3. Add this to your ~/.bashrc or ~/.zshrc

    grepcode() { find ~/code -type d -name .git | parallel "cd {.} && git grep --color -I --full-name -i '$@' | sed 's@^\(.*\):@{.}\1: @'"; }
  4. source ~/.bashrc or source ~/.zshrc

  5. Enjoy! eg: grepcode 'belongs_to.*blahblah'

2 Responses
Add your response

Had to add a semicolon to make it work in my ~/.profile on Mac OS X 10.8.4 but then it's great! Thanks for sharing

grepcode() {
        find ~/dev/repos -type d -name .git | parallel "cd {.} && git grep --color -I --full-name -i '$@' | sed 's@^\(.*\):@{.}\1: @'";
over 1 year ago ·

Thanks, I just added the ;

over 1 year ago ·