Primoz Cigler on Business and Code

PROTIP: Use `git grep`

git grep is amazing! You should start using it right now.

Here are several reasons why:

  • It is blazing fast. I doubt any code editor or IDE comes close to search in a terminal.
  • If you keep your repo lean and tidy, it will only search for your source files. Everything that’s not a source should not reside in the repository anyway (i.e. compiled css/js files, vendor/ by composer, bower_components/ by bower, node_modules/ by npm …)
  • You will be able to use different regex flavors for search.
  • You can easily filter down to specific file types.
  • You have docs at hand by typing git help grep.

Some examples

  • git grep -in 'my search string' – most frequently used, case-insensitive search with line numbers in results.
  • git grep 'my search string' -- **/*.scss – only search in .scss files anywhere in the repo.
  • git grep 'my search string' -- *.php – only search in .php in the root of the repo.
  • git grep -inE '#[a-f0-9]{3,6}' – find all instances of hexdec colors like #bada55 anywhere in your repo. Using extended regex. 😉

Seriously, it is amazing. Start using it right away. You will thank me later.

You’re welcome!

You should follow me on twitter, here.

Author

Primoz

A software engineer transitioning to a digital marketer and entrepreneur. Walking the talk. Windsurfer, digital nomad.