GIT-SED(1)

πŸ’… GIT-SED(1) β€” the Git Extras era

okay bestie, sit down, because git-sed is about to become your new obsession ✨


🌸 NAME 🌸

git-sed β€” swap out patterns inside files that git is tracking, no cap πŸ¦‹


✨ SYNOPSIS ✨

git-sed [ -c ] [ -f flags ] search replacement [ flags ] [ -- pathspec ]

πŸ’– DESCRIPTION πŸ’–

so here's the vibe: it runs git grep, takes whatever it found, and hands those results straight to sed so your patterns get replaced β€” with the flags you gave it, if you gave it any (either through -f or as that third argument, iykyk).

and if you pass -c? it also runs git commit for you. main character behavior, honestly πŸ‘‘


πŸŽ€ OPTIONS πŸŽ€

  • -c β€” commits the changes that come out of this, using a standard commit message that spells out the exact command you ran. ⚠️ it will fail if there are unstaged changes, so tidy up first bestie.
  • <flags> -f <flags> β€” uses these regex flags in the sed command. for example "g" replaces multiple times on the same line. (you can pass <flags> bare as the third argument too.)
  • <search> β€” the pattern that gets passed to grep and to the first part of the sed expression.
  • <replacement> β€” the replacement that gets passed to sed, aka the second part of the sed expression.
  • -- <pathspec> β€” limits which paths this gets applied to. for the supported patterns of pathspec, go read <https://git-scm.com/docs/gitglossary.html#Documentation/gitglossary.txt-aiddefpathspecapathspec> πŸ“–

🌈 EXAMPLES 🌈

$ git sed 'my_function' 'do_stuff'
# ... only does the changes, without committing
$ git commit -m"use proper function name"
$ git sed -c 'do_stuff' 'stuff'
# .. does the changes and a commit
$ git sed -f g do_stuff stuff
# .. g is actually pretty important, otherwise you will miss some
# stuff!
$ git sed 'my_method' 'do_stuff' -- lake/
# ... only replace 'my_method' occurs under lake/.

πŸ‘‘ AUTHOR πŸ‘‘

written by Antoine BeauprΓ© <anarcat@debian.org>, who was inspired by <https://github.com/da-x/git-search-replace> and <https://stackoverflow.com/questions/9651898/is-there-a-git-sed-or-equivalent> β€” absolute legends, fr fr πŸ™Œ


😭 REPORTING BUGS 😭

found something cursed? scream into the void here: <https://github.com/tj/git-extras/issues>


🫢 SEE ALSO 🫢


and that's the whole page, angel πŸ’œ this lil' masterpiece shipped in May 2026 as part of Git Extras β€” go forth and replace patterns responsibly, and remember: no -c without a clean working tree 🧚✨

πŸ“¦ where this page comes from