When using git-grep, the output isn't sorted alphabetically which makes navigating the results more tedious then it should be.

Is there a way to sort the output?

I checked git-grep and it seems there are no options to do this from within git itself.

1 Answer 1


Posting an answer to my own question, it's a works albeit a little hacky.

This simply pipes git-grep to sort.

Create an executable shell script wrapper for git: ~/.config/emacs/bin/git_sorted

exec git ${1+"$@"} | sort -V

And in your emacs.d/init.el:

  "~/.emacs.d/bin/git_sorted --no-pager grep --full-name -n --no-color -e %S")

sort -V happens to sort line numbers correctly (-n, -h... don't).

Note, it would be nice if there was a way to only sort the file-list which git-grep uses, instead of having to sort the entire output.

  • Could you please provide an example of the output before and after. I'm just curious
    – serghei
    Commented Dec 20, 2020 at 10:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.