Tutorial: ignoring Files from git grep

October 29, 2025 ยท View on GitHub

As a developer, when using git grep to search through my codebase, I want to ignore certain files or directories.

Maybe they contain non-useful information that still needs to be tracked with git, or maybe the files are too large and slow down the search.

git-grep can be configured to respect .gitattributes files for ignoring files. To do it, follow these steps:

  1. Create or edit a .gitattributes file in the root of your git repository. Add patterns for the files/directories you want to ignore. Example:

    # ignore the following from blink-ripgrep by giving them a specific attribute
    # that we then ignore in the git grep command.
    #
    # The name of the attribute does not matter and can be chosen by the user.
    subproject/file2.lua blink-ripgrep-ignore
    
    # ignore everything in this directory
    subproject/ignored-dir/** blink-ripgrep-ignore
    
  2. Configure blink-ripgrep to pass the appropriate options to git grep to ignore files with the specified attribute:

    require("blink-ripgrep").setup({
      backend = {
        gitgrep = {
          additional_gitgrep_options = {
            -- exclude files marked with the 'blink-ripgrep-ignore' attribute in
            -- .gitattributes
            ":(exclude,attr:blink-ripgrep-ignore)",
          },
        },
      },
    })
    

Resources