'git grep' and grep share the same options?

I have an alias in .bashrc for grep to contains grep options, e.g.,

alias grep='grep $GREP_OPTIONS'

I can't create an alias for git grep. What's the best way to let them share the same options?

1 answer

  • answered 2018-01-13 21:27 phd

    You certainly cannot have a bash alias with spaces:

    $ alias 'git grep'='git grep -F'
    bash: alias: `git grep': invalid alias name

    But you can use git's alias mechanism:

    git config --global alias.grep "grep -F"

    Now git stores the alias in your global .gitconfig (~/.gitconfig). Aliases in git are not recursive; when you run git grep git interprets that as git grep -F. The problem is there is now no way to run git grep without -F.