# Change the grep command called by git with alternative tools, such as ug.

5 messages from 2025-01-02 to 2025-01-02. Participants: Hongyi Zhao, Matěj Cepl, Jonathan Nieder.
Thread: https://gitlist.dev/t/62724

## Hongyi Zhao, 2025-01-02 11:48

Subject: Change the grep command called by git with alternative tools, such as ug.
Message-ID: <CAGP6POJX9GFsNkgGd7o9Pr-tFoz0sgRk51vVG4P0Kn1DPZe+3Q@mail.gmail.com>
URL: https://gitlist.dev/e/CAGP6POJX9GFsNkgGd7o9Pr-tFoz0sgRk51vVG4P0Kn1DPZe%2B3Q%40mail.gmail.com

```
Hi there,

Can I change the grep command called by git with alternative tools,
such as ug [1]?

Say in the following command:

$ git grep -i jobflow

I tried to replace grep with ug, but failed as follows:

$ git ug -i jobflow
git: 'ug' is not a git command. See 'git --help'.

The most similar command is
    gui


[1] https://github.com/Genivia/ugrep

Regards,
Zhao
-- 
Assoc. Prof. Hongsheng Zhao <hongyi.zhao@gmail.com>
Theory and Simulation of Materials
Hebei Vocational University of Technology and Engineering
No. 473, Quannan West Street, Xindu District, Xingtai, Hebei province

```

## Matěj Cepl, 2025-01-02 13:00

Subject: Re: Change the grep command called by git with alternative tools, such as ug.
Message-ID: <D6RLU4BY374I.GQY9MLMV1AZJ@cepl.eu>
URL: https://gitlist.dev/e/D6RLU4BY374I.GQY9MLMV1AZJ%40cepl.eu
In-Reply-To: <CAGP6POJX9GFsNkgGd7o9Pr-tFoz0sgRk51vVG4P0Kn1DPZe+3Q@mail.gmail.com>

```
On Thu Jan 2, 2025 at 12:49 PM CET, Hongyi Zhao wrote:
> $ git grep -i jobflow
>
> I tried to replace grep with ug, but failed as follows:

AFAIK, git grep doesn’t use external grep(1) binary on its
own, but rather it uses its own (and slightly different)
algorithm. Certainly, calling git-ug (or git-rg) will do
absolutely nothing as long as you have no git-ug binary in your
$PATH.

Best,

Matěj

-- 
http://matej.ceplovi.cz/blog/, @mcepl@en.osm.town
GPG Finger: 3C76 A027 CA45 AD70 98B5  BC1D 7920 5802 880B C9D8
 
When God put a calling on your life, He already factored in your
stupidity.
  -- Unknown, mentioned in a sermon


```

## Hongyi Zhao, 2025-01-02 13:39

Subject: Re: Change the grep command called by git with alternative tools, such as ug.
Message-ID: <CAGP6POKLdTpwsaGo-oyGAiYJMRzwXN06rv3+V7v5QbL6xtDROw@mail.gmail.com>
URL: https://gitlist.dev/e/CAGP6POKLdTpwsaGo-oyGAiYJMRzwXN06rv3%2BV7v5QbL6xtDROw%40mail.gmail.com
In-Reply-To: <D6RLU4BY374I.GQY9MLMV1AZJ@cepl.eu>

```
On Thu, Jan 2, 2025 at 9:00 PM Matěj Cepl <mcepl@cepl.eu> wrote:
>
> On Thu Jan 2, 2025 at 12:49 PM CET, Hongyi Zhao wrote:
> > $ git grep -i jobflow
> >
> > I tried to replace grep with ug, but failed as follows:
>
> AFAIK, git grep doesn’t use external grep(1) binary on its
> own, but rather it uses its own (and slightly different)
> algorithm. Certainly, calling git-ug (or git-rg) will do
> absolutely nothing as long as you have no git-ug binary in your
> $PATH.

Do you mean: by linking ug as git-ug will do the trick?

> Best,
>
> Matěj

Zhao

```

## Matěj Cepl, 2025-01-02 14:57

Subject: Re: Change the grep command called by git with alternative tools, such as ug.
Message-ID: <D6ROC4RAYQS1.3V2K2W5GMAEYR@cepl.eu>
URL: https://gitlist.dev/e/D6ROC4RAYQS1.3V2K2W5GMAEYR%40cepl.eu
In-Reply-To: <CAGP6POKLdTpwsaGo-oyGAiYJMRzwXN06rv3+V7v5QbL6xtDROw@mail.gmail.com>

```
On Thu Jan 2, 2025 at 2:39 PM CET, Hongyi Zhao wrote:
> Do you mean: by linking ug as git-ug will do the trick?

No, you would have to rewrite git-grep to use external grep-like
program. I am not sure whether there isn’t such project already
out there.

Best,

Matěj

-- 
http://matej.ceplovi.cz/blog/, @mcepl@en.osm.town
GPG Finger: 3C76 A027 CA45 AD70 98B5  BC1D 7920 5802 880B C9D8
 
To the well-organized mind, death is but the next great adventure.
  -- Albus Dumbledore


```

## Jonathan Nieder, 2025-01-02 15:28

Subject: Re: Change the grep command called by git with alternative tools, such as ug.
Message-ID: <Z3awl9gToJjwap-G@google.com>
URL: https://gitlist.dev/e/Z3awl9gToJjwap-G%40google.com
In-Reply-To: <D6ROC4RAYQS1.3V2K2W5GMAEYR@cepl.eu>

```
Hi,

Matěj Cepl wrote:
> On Thu Jan 2, 2025 at 2:39 PM CET, Hongyi Zhao wrote:

>> Do you mean: by linking ug as git-ug will do the trick?
>
> No, you would have to rewrite git-grep to use external grep-like
> program. I am not sure whether there isn’t such project already
> out there.

The key question is - what are you trying to do?  "git grep" is able
to search inside historical commits, the working copy, the index, and
so on.  Do we want to search in the same way to find files with hits
(for efficiency reasons, for example) and then use an external program
to find the matches within those files?  For that kind of application
I might do some scripting around "git grep --name-only", but I can
also imagine that your application is different.  Depending on the
goal, it could be something a git command already supports, an implied
feature request for git, or something that the external search tool
might need to learn.

In other words, Matěj's reply is spot on in describing the current
behavior: "git grep" doesn't call out to an external grep tool.  But
as for the desired behavior, we'd need to know more about the use case
to figure it out.

Thanks,
Jonathan

```
