{"thread":{"id":"64346","subject":"Making git grep ignore binary the default","startedAt":"2025-10-17T15:00:41Z","lastAt":"2025-10-21T07:27:51Z","messageCount":10,"participants":["El_Hoy","Junio C Hamano","Thomas Braun","brian m. carlson","Jeff King","rsbecker@nexbridge.com"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"529079","messageId":"CAPapNH0C3+bU-RUO6oFHUKLjKuNdm-aXgsFTHFobYVrJXWzr=g@mail.gmail.com","threadId":"64346","inReplyTo":null,"subject":"Making git grep ignore binary the default","fromName":"El_Hoy","fromEmail":"eloyesp@gmail.com","sentAt":"2025-10-17T15:00:27Z","receivedAt":"2025-10-17T15:00:41Z","isPatch":false,"sender":{"key":"eloyesp@gmail.com","avatar":"https://gravatar.com/avatar/d925a85ccf59e6edcfc943f7fdbefcb75dcaac0b5b7b00642a79d9c6e8f24036?d=mp&s=160"},"body":"I've found that there is a flag (`git grep -I`) to ignore binary\nfiles, it works great, but I've found no way to make it the default.\n\nIt would be great to have a config for this. This way a possible\nimplementation implies:\n\n- Adding a config `grep.ignoreBinary` that defaults to false, keeping\nthe current default.\n\n- Adding a flag `git grep --include-binary` to revert the default. But\nmaybe the `-a, --text` flag already does that.\n\nAlso, maybe the next git version (3.0) can default to ignore-binary as\na better default.\n\nFinally, if this makes sense, I can do my best to implement the change\nin the code.\n\nRegards.\n- Eloy\n"},{"id":"529103","messageId":"xmqqsefhxlmd.fsf@gitster.g","threadId":"64346","inReplyTo":"CAPapNH0C3+bU-RUO6oFHUKLjKuNdm-aXgsFTHFobYVrJXWzr=g@mail.gmail.com","subject":"Re: Making git grep ignore binary the default","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2025-10-17T21:29:46Z","receivedAt":"2025-10-17T21:29:49Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"El_Hoy <eloyesp@gmail.com> writes:\n\n> I've found that there is a flag (`git grep -I`) to ignore binary\n> files, it works great, but I've found no way to make it the default.\n>\n> It would be great to have a config for this. This way a possible\n> implementation implies:\n>\n> - Adding a config `grep.ignoreBinary` that defaults to false, keeping\n> the current default.\n>\n> - Adding a flag `git grep --include-binary` to revert the default. But\n> maybe the `-a, --text` flag already does that.\n>\n> Also, maybe the next git version (3.0) can default to ignore-binary as\n> a better default.\n\nI am tempted to suggest not to do any of the above.\n\nSimply because we have never needed to do something similar to \"-a\"\nand \"-I\" that we added in early 2006 for the past nearly 20 years.\nAlso because GNU does not have any such thing to force \"-a\" or \"-I\"\nas default.  The biggest reason is that it would be surprising if\nsuch a change does not break existing scripts that have been written\nby people over the years.\n\n\n\n"},{"id":"529108","messageId":"0de410fa-22ef-4495-a6a9-dcd33a329201@virtuell-zuhause.de","threadId":"64346","inReplyTo":"xmqqsefhxlmd.fsf@gitster.g","subject":"Re: Making git grep ignore binary the default","fromName":"Thomas Braun","fromEmail":"thomas.braun@virtuell-zuhause.de","sentAt":"2025-10-17T23:29:22Z","receivedAt":"2025-10-17T23:51:02Z","isPatch":false,"sender":{"key":"thomas.braun@virtuell-zuhause.de","avatar":"https://avatars.githubusercontent.com/u/1185677?v=4"},"body":"Am 17.10.2025 um 23:29 schrieb Junio C Hamano:\n> El_Hoy <eloyesp@gmail.com> writes:\n>\n>> I've found that there is a flag (`git grep -I`) to ignore binary\n>> files, it works great, but I've found no way to make it the default.\n>>\n>> It would be great to have a config for this. This way a possible\n>> implementation implies:\n>>\n>> - Adding a config `grep.ignoreBinary` that defaults to false, keeping\n>> the current default.\n>>\n>> - Adding a flag `git grep --include-binary` to revert the default. But\n>> maybe the `-a, --text` flag already does that.\n>>\n>> Also, maybe the next git version (3.0) can default to ignore-binary as\n>> a better default.\n> I am tempted to suggest not to do any of the above.\n>\n> Simply because we have never needed to do something similar to \"-a\"\n> and \"-I\" that we added in early 2006 for the past nearly 20 years.\n> Also because GNU does not have any such thing to force \"-a\" or \"-I\"\n> as default.  The biggest reason is that it would be surprising if\n> such a change does not break existing scripts that have been written\n> by people over the years.\n\nAnd if we only would have the config option \"grep.ignoreBinary\" \ndefaulting to false with no default change whatsoever? I always want to \nignore binaries when grepping and find it a bit tedious that I have to \nspell it out all over again. And yes I do have an alias as well but \nusually don't remember to use it.\n\nI'm also curious what people are looking for in binary files with git grep.\n\n"},{"id":"529109","messageId":"aPLkuPgirAVHkERr@fruit.crustytoothpaste.net","threadId":"64346","inReplyTo":"0de410fa-22ef-4495-a6a9-dcd33a329201@virtuell-zuhause.de","subject":"Re: Making git grep ignore binary the default","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2025-10-18T00:52:08Z","receivedAt":"2025-10-18T00:52:17Z","isPatch":false,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"On 2025-10-17 at 23:29:22, Thomas Braun wrote:\n> Am 17.10.2025 um 23:29 schrieb Junio C Hamano:\n> > Simply because we have never needed to do something similar to \"-a\"\n> > and \"-I\" that we added in early 2006 for the past nearly 20 years.\n> > Also because GNU does not have any such thing to force \"-a\" or \"-I\"\n> > as default.  The biggest reason is that it would be surprising if\n> > such a change does not break existing scripts that have been written\n> > by people over the years.\n> \n> And if we only would have the config option \"grep.ignoreBinary\" defaulting\n> to false with no default change whatsoever? I always want to ignore binaries\n> when grepping and find it a bit tedious that I have to spell it out all over\n> again. And yes I do have an alias as well but usually don't remember to use\n> it.\n\nAs Junio said, this could break existing scripts.  If I write a command\nwhich uses `git grep` and expects to find all matching files, it would\nnot work on your system with `grep.ignoreBinary` set to true.\n\nFor instance, if I am working on a project for a company and must\nexclude source code with a certain vendor's copyright (because we don't\nhave permission to distribute their code), then it would be very bad if\nI accidentally distributed that company's binary files due to `git grep\n-l PATTERN | xargs rm -f` not matching them since it would violate the\nlicense.\n\nThis is just an example, but there are lots of cases where people do\nreally want to search every file.\n\n> I'm also curious what people are looking for in binary files with git grep.\n\nIt's common to mark PDFs or PostScript files as binary because they\noften contain embedded binary fonts, but they are actually mostly text\nand can be usefully searched with grep.  For instance, I once created\nsome awards for a non-profit based on combining standalone text-based\nPostScript code along with output from groff, so those independent\npieces could end up being source that you might store in Git and search,\neven if many configurations would use `*.ps -text` in a system\ngitattributes file.\n\nSometimes you also have images or such for a website, which contain XMP\nmetadata (a form of XML-serialized RDF).  Finding those images which\nhave certain author metadata or a certain license URL embedded in them\ncould be valuable.\n-- \nbrian m. carlson (they/them)\nToronto, Ontario, CA\n"},{"id":"529124","messageId":"20251018102209.GH1060824@coredump.intra.peff.net","threadId":"64346","inReplyTo":"xmqqsefhxlmd.fsf@gitster.g","subject":"Re: Making git grep ignore binary the default","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2025-10-18T10:22:09Z","receivedAt":"2025-10-18T10:22:14Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Fri, Oct 17, 2025 at 02:29:46PM -0700, Junio C Hamano wrote:\n\n> Simply because we have never needed to do something similar to \"-a\"\n> and \"-I\" that we added in early 2006 for the past nearly 20 years.\n> Also because GNU does not have any such thing to force \"-a\" or \"-I\"\n> as default.  The biggest reason is that it would be surprising if\n> such a change does not break existing scripts that have been written\n> by people over the years.\n\nI do think there is one difference between git-grep and regular grep\nhere: the input file selection.\n\nIn \"grep\", the default set of files to search is nothing, and you have\nto tell it which files to look at. So aside from overly broad globs, the\nproblem solves itself when you just don't pass in the binary paths.\n\nBut in git-grep, the default set of files to search is everything in the\nrepository! So it is very easy to noisy hits from uninteresting files.\n\nI think binary-ness of the files is a red herring, though. There are\nplenty of text files that are not interesting to grep either. I almost\nnever want to see hits from po/ in git.git, for example. I get by with\n\"^po/\", or even \"'*.c'\" (extra single-quotes so that Git expands the\nglob). But I'd be happy if I could set a configuration knob to say that\nfiles with attribute X should be omitted from grep results (whether\nbinary, or some custom attribute that I assign in .git/info/attributes).\n\nI think we've discussed this before, and digging in the archive found\nthis thread from 2012:\n\n  https://lore.kernel.org/git/4f1d2a8b.a2d8320a.50ec.576d@mx.google.com/\n\nI think some of those ideas came to fruition. You can do:\n\n  git grep ':(attr:!binary)'\n\nnow (which obviously is harder than \"-I\", but the point is that it\nextends to any attribute if you want). But I still think it would be\nnice if there was a way to make it the default (without using an alias).\n\n-Peff\n"},{"id":"529126","messageId":"00af01dc4039$dd45e090$97d1a1b0$@nexbridge.com","threadId":"64346","inReplyTo":"aPLkuPgirAVHkERr@fruit.crustytoothpaste.net","subject":"RE: Making git grep ignore binary the default","fromName":"","fromEmail":"rsbecker@nexbridge.com","sentAt":"2025-10-18T14:16:52Z","receivedAt":"2025-10-18T14:27:26Z","isPatch":false,"sender":{"key":"randall.becker@nexbridge.ca","avatar":"https://avatars.githubusercontent.com/u/28956764?v=4"},"body":"On October 17, 2025 8:52 PM, brian m. carlson wrote:\n>On 2025-10-17 at 23:29:22, Thomas Braun wrote:\n>> Am 17.10.2025 um 23:29 schrieb Junio C Hamano:\n>> > Simply because we have never needed to do something similar to \"-a\"\n>> > and \"-I\" that we added in early 2006 for the past nearly 20 years.\n>> > Also because GNU does not have any such thing to force \"-a\" or \"-I\"\n>> > as default.  The biggest reason is that it would be surprising if\n>> > such a change does not break existing scripts that have been written\n>> > by people over the years.\n>>\n>> And if we only would have the config option \"grep.ignoreBinary\"\n>> defaulting to false with no default change whatsoever? I always want\n>> to ignore binaries when grepping and find it a bit tedious that I have\n>> to spell it out all over again. And yes I do have an alias as well but\n>> usually don't remember to use it.\n>\n>As Junio said, this could break existing scripts.  If I write a command which uses `git\n>grep` and expects to find all matching files, it would not work on your system with\n>`grep.ignoreBinary` set to true.\n>\n>For instance, if I am working on a project for a company and must exclude source\n>code with a certain vendor's copyright (because we don't have permission to\n>distribute their code), then it would be very bad if I accidentally distributed that\n>company's binary files due to `git grep -l PATTERN | xargs rm -f` not matching them\n>since it would violate the license.\n>\n>This is just an example, but there are lots of cases where people do really want to\n>search every file.\n>\n>> I'm also curious what people are looking for in binary files with git grep.\n>\n>It's common to mark PDFs or PostScript files as binary because they often contain\n>embedded binary fonts, but they are actually mostly text and can be usefully\n>searched with grep.  For instance, I once created some awards for a non-profit\n>based on combining standalone text-based PostScript code along with output from\n>groff, so those independent pieces could end up being source that you might store\n>in Git and search, even if many configurations would use `*.ps -text` in a system\n>gitattributes file.\n>\n>Sometimes you also have images or such for a website, which contain XMP\n>metadata (a form of XML-serialized RDF).  Finding those images which have certain\n>author metadata or a certain license URL embedded in them could be valuable.\n\nI agree that this will break scripts. There are quasi-binary files in some SQL\nspaces that really benefit from git grep working. Please do not make this the\ndefault.\n\n"},{"id":"529130","messageId":"xmqq347gw65j.fsf@gitster.g","threadId":"64346","inReplyTo":"20251018102209.GH1060824@coredump.intra.peff.net","subject":"Re: Making git grep ignore binary the default","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2025-10-18T16:01:28Z","receivedAt":"2025-10-18T16:01:30Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jeff King <peff@peff.net> writes:\n\n> I think we've discussed this before, and digging in the archive found\n> this thread from 2012:\n>\n>   https://lore.kernel.org/git/4f1d2a8b.a2d8320a.50ec.576d@mx.google.com/\n>\n> I think some of those ideas came to fruition. You can do:\n>\n>   git grep ':(attr:!binary)'\n>\n> now (which obviously is harder than \"-I\", but the point is that it\n> extends to any attribute if you want). But I still think it would be\n> nice if there was a way to make it the default (without using an alias).\n\nYeah, after I re-read the thread, I specially liked the \"filetype\"\nidea that you floated in\n\n  https://lore.kernel.org/git/20120125214625.GA4666@sigill.intra.peff.net/\n\n;-).\n"},{"id":"529173","messageId":"0ef23314ca63d03467a50a93d2db1db3ad950ede.camel@virtuell-zuhause.de","threadId":"64346","inReplyTo":"aPLkuPgirAVHkERr@fruit.crustytoothpaste.net","subject":"Re: Making git grep ignore binary the default","fromName":"Thomas Braun","fromEmail":"thomas.braun@virtuell-zuhause.de","sentAt":"2025-10-20T15:24:03Z","receivedAt":"2025-10-20T15:24:12Z","isPatch":false,"sender":{"key":"thomas.braun@virtuell-zuhause.de","avatar":"https://avatars.githubusercontent.com/u/1185677?v=4"},"body":"Am Samstag, dem 18.10.2025 um 00:52 +0000 schrieb brian m. carlson:\n> On 2025-10-17 at 23:29:22, Thomas Braun wrote:\n> > Am 17.10.2025 um 23:29 schrieb Junio C Hamano:\n> > > Simply because we have never needed to do something similar to \"-\n> > > a\"\n> > > and \"-I\" that we added in early 2006 for the past nearly 20\n> > > years.\n> > > Also because GNU does not have any such thing to force \"-a\" or \"-\n> > > I\"\n> > > as default.  The biggest reason is that it would be surprising if\n> > > such a change does not break existing scripts that have been\n> > > written\n> > > by people over the years.\n> > \n> > And if we only would have the config option \"grep.ignoreBinary\"\n> > defaulting\n> > to false with no default change whatsoever? I always want to ignore\n> > binaries\n> > when grepping and find it a bit tedious that I have to spell it out\n> > all over\n> > again. And yes I do have an alias as well but usually don't\n> > remember to use\n> > it.\n> \n> As Junio said, this could break existing scripts.  If I write a\n> command which uses `git grep` and expects to find all matching files,\n> it would not work on your system with `grep.ignoreBinary` set to\n> true.\n> \n> For instance, if I am working on a project for a company and must\n> exclude source code with a certain vendor's copyright (because we\n> don't have permission to distribute their code), then it would be\n> very bad if I accidentally distributed that company's binary files\n> due to `git grep -l PATTERN | xargs rm -f` not matching them since it\n> would violate the license.\n> \n> This is just an example, but there are lots of cases where people do\n> really want to search every file.\n\nI understand your use case. But if you don't control the environment\n(git config settings among others) your task of finding things reliably\nwill just very easily break.\n\nAlso in your use case, I either opted in to ignoring binary files, so I\nshould be wary of scripts assuming binary files are searched or I did\nnot and then nothing changes.\n\n> > I'm also curious what people are looking for in binary files with\n> > git grep.\n> \n> It's common to mark PDFs or PostScript files as binary because they\n> often contain embedded binary fonts, but they are actually mostly\n> text\n> and can be usefully searched with grep.  For instance, I once created\n> some awards for a non-profit based on combining standalone text-based\n> PostScript code along with output from groff, so those independent\n> pieces could end up being source that you might store in Git and\n> search,\n> even if many configurations would use `*.ps -text` in a system\n> gitattributes file.\n> \n> Sometimes you also have images or such for a website, which contain\n> XMP metadata (a form of XML-serialized RDF).  Finding those images\n> which have certain author metadata or a certain license URL embedded\n> in them could be valuable.\n\nThanks for the examples.\n\nThe previous discussion dug up by Junio and Peff was an interesting\nread. But from my understanding adding a git attribute like grep, which\nallows to ignore \"uninteresting\" files for grep, does not solve your\nbackward compatibility concerns. Changing that looks easier now to be\ndone in 2012 comared to 2025 ;)\n"},{"id":"529180","messageId":"CAPapNH2UeRoKF9Tm5my59MXCxUQqEp+=4wzod8kYus_FQALwjQ@mail.gmail.com","threadId":"64346","inReplyTo":"0ef23314ca63d03467a50a93d2db1db3ad950ede.camel@virtuell-zuhause.de","subject":"Re: Making git grep ignore binary the default","fromName":"El_Hoy","fromEmail":"eloyesp@gmail.com","sentAt":"2025-10-20T17:20:06Z","receivedAt":"2025-10-20T17:20:21Z","isPatch":false,"sender":{"key":"eloyesp@gmail.com","avatar":"https://gravatar.com/avatar/d925a85ccf59e6edcfc943f7fdbefcb75dcaac0b5b7b00642a79d9c6e8f24036?d=mp&s=160"},"body":"Ok, so if I understand correctly:\n\n1. changing the default grep behaviour is not acceptable because it might\nbreak existing scripts.\n2. Adding a config option might break a shared script on specific computers\nbut that seems more reasonable.\n3. There may be better ways to implement the setting that allow more\nflexibility.\n\nRegarding point 1, I thought about this as a possible idea for a distant future\nwith proper warnings, because I think this is a better default, but if\nthe cost of\nmaking such a change is too big, we can omit this. If someone wants to come\nback to this, it might make sense to \"grep\" public code and check how much\ncode would be affected to have more clarity about the costs.\n\nOn point 2, as Thomas points, there are many factors that might break a script\nthat rely on 'git grep' directly for a dangerous task, this makes me\nthink that we\ncould add a `--porcelain` option to `git grep` to be used on scripts\nand be reliable,\nand it might ignore the config.\n\nOn point 3, the configuration could be made with more flexibility in\nmind, making\nit possible to ignore different files that are not binary (for example\nlinguist-generated\nfiles). The downside of that approach is that it requires more\nconfiguration, while\na single boolean for skipping binaries might be simpler. I'm ok with\nany approach.\n\nThat said, it seems important to add a flag to negate that setting for\na single run, so\nif I have the setting to skip from grep some files, there should be a\nway to run grep on\nall the files, ignoring this setting, as it is also needed from time to time.\n\nRegards.\n\n\n---  Eloy\n\nOn Mon, Oct 20, 2025 at 12:24 PM Thomas Braun\n<thomas.braun@virtuell-zuhause.de> wrote:\n>\n> Am Samstag, dem 18.10.2025 um 00:52 +0000 schrieb brian m. carlson:\n> > On 2025-10-17 at 23:29:22, Thomas Braun wrote:\n> > > Am 17.10.2025 um 23:29 schrieb Junio C Hamano:\n> > > > Simply because we have never needed to do something similar to \"-\n> > > > a\"\n> > > > and \"-I\" that we added in early 2006 for the past nearly 20\n> > > > years.\n> > > > Also because GNU does not have any such thing to force \"-a\" or \"-\n> > > > I\"\n> > > > as default.  The biggest reason is that it would be surprising if\n> > > > such a change does not break existing scripts that have been\n> > > > written\n> > > > by people over the years.\n> > >\n> > > And if we only would have the config option \"grep.ignoreBinary\"\n> > > defaulting\n> > > to false with no default change whatsoever? I always want to ignore\n> > > binaries\n> > > when grepping and find it a bit tedious that I have to spell it out\n> > > all over\n> > > again. And yes I do have an alias as well but usually don't\n> > > remember to use\n> > > it.\n> >\n> > As Junio said, this could break existing scripts.  If I write a\n> > command which uses `git grep` and expects to find all matching files,\n> > it would not work on your system with `grep.ignoreBinary` set to\n> > true.\n> >\n> > For instance, if I am working on a project for a company and must\n> > exclude source code with a certain vendor's copyright (because we\n> > don't have permission to distribute their code), then it would be\n> > very bad if I accidentally distributed that company's binary files\n> > due to `git grep -l PATTERN | xargs rm -f` not matching them since it\n> > would violate the license.\n> >\n> > This is just an example, but there are lots of cases where people do\n> > really want to search every file.\n>\n> I understand your use case. But if you don't control the environment\n> (git config settings among others) your task of finding things reliably\n> will just very easily break.\n>\n> Also in your use case, I either opted in to ignoring binary files, so I\n> should be wary of scripts assuming binary files are searched or I did\n> not and then nothing changes.\n>\n> > > I'm also curious what people are looking for in binary files with\n> > > git grep.\n> >\n> > It's common to mark PDFs or PostScript files as binary because they\n> > often contain embedded binary fonts, but they are actually mostly\n> > text\n> > and can be usefully searched with grep.  For instance, I once created\n> > some awards for a non-profit based on combining standalone text-based\n> > PostScript code along with output from groff, so those independent\n> > pieces could end up being source that you might store in Git and\n> > search,\n> > even if many configurations would use `*.ps -text` in a system\n> > gitattributes file.\n> >\n> > Sometimes you also have images or such for a website, which contain\n> > XMP metadata (a form of XML-serialized RDF).  Finding those images\n> > which have certain author metadata or a certain license URL embedded\n> > in them could be valuable.\n>\n> Thanks for the examples.\n>\n> The previous discussion dug up by Junio and Peff was an interesting\n> read. But from my understanding adding a git attribute like grep, which\n> allows to ignore \"uninteresting\" files for grep, does not solve your\n> backward compatibility concerns. Changing that looks easier now to be\n> done in 2012 comared to 2025 ;)\n"},{"id":"529223","messageId":"20251021072740.GA259661@coredump.intra.peff.net","threadId":"64346","inReplyTo":"CAPapNH2UeRoKF9Tm5my59MXCxUQqEp+=4wzod8kYus_FQALwjQ@mail.gmail.com","subject":"Re: Making git grep ignore binary the default","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2025-10-21T07:27:40Z","receivedAt":"2025-10-21T07:27:51Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Mon, Oct 20, 2025 at 02:20:06PM -0300, El_Hoy wrote:\n\n> On point 2, as Thomas points, there are many factors that might break\n> a script that rely on 'git grep' directly for a dangerous task, this\n> makes me think that we could add a `--porcelain` option to `git grep`\n> to be used on scripts and be reliable, and it might ignore the config.\n\nAnother option here is to provide a way for scripts to override the\nignore mechanism specifically (which would depend on how it is\nimplemented). For an example, see below.\n\n> On point 3, the configuration could be made with more flexibility in\n> mind, making it possible to ignore different files that are not binary\n> (for example linguist-generated files). The downside of that approach\n> is that it requires more configuration, while a single boolean for\n> skipping binaries might be simpler. I'm ok with any approach.\n\nOne way to do this would be to provide a default pathspec for git-grep\nwhen one is not defined. Something like:\n\ndiff --git a/builtin/grep.c b/builtin/grep.c\nindex 13841fbf00..7b6a6ba9c6 100644\n--- a/builtin/grep.c\n+++ b/builtin/grep.c\n@@ -42,6 +42,7 @@ static char const * const grep_usage[] = {\n };\n \n static int recurse_submodules;\n+static struct strvec default_pathspec = STRVEC_INIT;\n \n static int num_threads;\n \n@@ -320,6 +321,15 @@ static int grep_cmd_config(const char *var, const char *value,\n \tif (!strcmp(var, \"submodule.recurse\"))\n \t\trecurse_submodules = git_config_bool(var, value);\n \n+\tif (!strcmp(var, \"grep.defaultpathspec\")) {\n+\t\tif (!value)\n+\t\t\treturn config_error_nonbool(var);\n+\t\telse if (*value)\n+\t\t\tstrvec_push(&default_pathspec, value);\n+\t\telse\n+\t\t\tstrvec_clear(&default_pathspec);\n+\t}\n+\n \treturn st;\n }\n \n@@ -1169,7 +1179,7 @@ int cmd_grep(int argc,\n \tparse_pathspec(&pathspec, 0,\n \t\t       PATHSPEC_PREFER_CWD |\n \t\t       (opt.max_depth != -1 ? PATHSPEC_MAXDEPTH_VALID : 0),\n-\t\t       prefix, argv + i);\n+\t\t       prefix, i < argc ? argv + i : default_pathspec.v);\n \tpathspec.max_depth = opt.max_depth;\n \tpathspec.recursive = 1;\n \tpathspec.recurse_submodules = !!recurse_submodules;\n\nBuilding with that lets you do something like this in git.git:\n\n  $ ./git grep 'added by us:'\n  po/bg.po:msgid \"added by us:\"\n  po/ca.po:msgid \"added by us:\"\n  po/de.po:msgid \"added by us:\"\n  po/el.po:msgid \"added by us:\"\n  po/es.po:msgid \"added by us:\"\n  po/fr.po:msgid \"added by us:\"\n  po/ga.po:msgid \"added by us:\"\n  po/id.po:msgid \"added by us:\"\n  po/it.po:msgid \"added by us:\"\n  po/ko.po:msgid \"added by us:\"\n  po/pl.po:msgid \"added by us:\"\n  po/pt_PT.po:msgid \"added by us:\"\n  po/ru.po:msgid \"added by us:\"\n  po/sv.po:msgid \"added by us:\"\n  po/tr.po:msgid \"added by us:\"\n  po/uk.po:msgid \"added by us:\"\n  po/vi.po:msgid \"added by us:\"\n  po/zh_CN.po:msgid \"added by us:\"\n  po/zh_TW.po:msgid \"added by us:\"\n  t/t7060-wtstatus.sh:    added by us:     sub_second.txt\n  wt-status.c:            return _(\"added by us:\");\n\n  $ git config grep.defaultPathspec :^po\n  $ ./git grep 'added by us:'\n  t/t7060-wtstatus.sh:    added by us:     sub_second.txt\n  wt-status.c:            return _(\"added by us:\");\n\nAnd then scripts override it by providing a pathspec (like \".\" if they\nwant to see everything, which conveniently also works on old versions of\nGit).\n\nIt isn't _quite_ the same as an option to ignore certain paths, as it's\na default replacement, and not additive (so as soon as I ask for\neverything in \"foo/\", then \"foo/bar\" will be included even if I have\n\"^foo/bar\" in my default pathspec). I'm not sure if that is a drawback\nor a feature.\n\nThere may be other rough edges. It's not something I've thought that\ncarefully about yet. But it just gives an idea of a possible direction.\n\nOf course you can already do the same thing with an alias right now[1].\nYou just need to remember to type the alias instead of \"grep\". That\nrequires some finger retraining, but it would eliminate any script /\ncompatibility questions.\n\n-Peff\n\n[1] The alias isn't quite trivial because we want to add our pathspecs\n    at the _end_ of the command-line. But I think something like:\n\n      [alias]\n      gr = \"!f() { exec git grep \\\"$@\\\" :^po; }; f\"\n\n    works.\n"}]}