git search | grep and ls-files

Git | How do I Search For Strings, Files and Folders

These commands search the entire project in your working copy – that’s the simple way – but you can get funky and search all manner of corners using certain modifiers.

It doesn’t matter at which directory level you are – unlike the Linux grep command that searches the folder you are in (or recursively below with a -r switch).

  1. git ls-files *.html » to find all html files
  2. git grep simple » to search (project) for lines containing “simple”
  3. git grep -in simple » case insensitive search for “simple” (with line numbers printed)
  4. git grep simple -- *.html » search for “simple” in html files
  5. git grep -in "simple " -- *.java » simple followed by space in java files

get funky and search all manner of corners

You can search files that have been deleted, ignored, staged, not yet merged and even modified using switches like below.

–[cached|deleted|others|ignored|stage|unmerged|killed|modified]
-[c|d|o|i|s|u|k|m]

Simple Git

Git can be over-complicated so here are “simple as” listings command groups that deliver observable value.
Just because you can (handle complexity) does not mean you should.

You want your brain working on your domain – not fighting with abstract version control concepts. These 7 things are what you’ll do with Git 90% of the time.

Leave a Reply

Your email address will not be published. Required fields are marked *