Skip to main content

a utility on top of git for project-wide search-and-replace that includes filenames too

Project description


git-search-replace is a small utility on top of plain git for performing project-wide search-and-replace only on git-controlled files. It applies its searches to filenames as well as their content. The underlying syntax for the search regex is Python’s.

It is designed to be a bit more instructive to the developer, compared to hackish bash scripts around sed.

Key features are:

  • By default, only act as grep to show what is going to change.
  • Dry run mode ‘–diff’ shows a unidiff of the changes that the search-and-replace would do, so that the developer can review for correctness. No working directory files are modified.
  • Fix mode ‘–fix’ performs the actual changes and associated ‘git mv’.


Usage: gsr [options] (FROM-SEPARATOR-TO…)

-h, --help show this help message and exit
-s STRING, --separator=STRING
 The separator string which separates FROM regex and TO expression
-f, --fix Perform changes in-place
-d, --diff Use ‘diff’ util to show differences

The expressions are tuples in the form of FROM-SEPARATOR-TO, with SEPARATOR defaults to ‘///’.


Shell escaping needs to be taken into consideration. The examples below should work with the major UNIX shells.

gsr old_name///new_name –diff

This shows a diff that represents the replacement of ‘old_name’ with ‘new_name’.

gsr \bold_name\b///new_name –fix

This uses Python regex expression b for matching at word boundaries for whole identifiers. This invocation will perform changes in-place because of ‘–fix’.

gsr ‘things with space///with other stuff’ –diff

Note that shells properly de-escape the commas from the expression above.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for git-search-replace, version 1.0.2
Filename, size File type Python version Upload date Hashes
Filename, size git-search-replace-1.0.2.tar.gz (3.7 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page