Jason Meridth

I am a continuously learning senior full stack SDE/SRE trying to not let best be the enemy of better.

Use Git Grep to Replace Strings in Files in Your Git Repository

11 Feb 2013 » » git


On Linux:

git grep -l 'original_text' | xargs sed -i 's/original_text/new_text/g'

On Mac:

git grep -l 'original_text' | xargs sed -i '' -e 's/original_text/new_text/g'

I needed to change a string in a bunch of files and I used the command above using git grep to do it. Worked like a charm.

The -l argument to git grep only returns the file names and not the location in the file like it usually does.

The -e argument is needed with the sed portion on OSX as stated by asmeurer in the comments