One Script, Many Repositories: Easy Refactoring
Today I ran into a classic engineering headache: updating the same variable or function name across a bunch of different repositories. If you’ve had to update a variable name in a dozen microservices, you know how tedious and error-prone it can be. Open each repo, make the change, push a branch, open a PR... repeat until your coffee gets cold ☕️.
I decided enough was enough and put together a script to automate the whole thing. The idea is simple: give it a list of repos, tell it what you want to replace (old function, variable, whatever), and let it do the boring work. It’ll clone each repo, make the change with sed, commit to a new branch, push, and even open a pull request for you using the GitHub CLI. No more repetitive clicking or copy-pasting.
A few things to set up first: you’ll need git, the GitHub CLI (gh), and SSH access to your repos. The script uses BSD sed by default (macOS style), so tweak it if you’re on Linux. You can run it directly as a shell script or use the Python wrapper if you want a slightly nicer interface.
The workflow is straightforward:
- Clone each repo into a temp workspace locally.
- Check out the base branch (like
mainordevelop), pull the latest, and create a feature branch. - Run the find-and-replace.
- Commit, push, and open a PR.
- Clean up and move to the next repo.
Pro tip: test on a single repo first to make sure your sed command does what you expect! If you want to get fancy, you can customize the PR body or target branch per repo.
Honestly, this little automation has already saved me hours. If you’re tired of manual updates across multiple codebases, give it a try.