Keeping on top of changes across multiple git repositories

This is a classic "I scratched my itch, hope it helps" story. I made a Github Gist out of it.

I sometimes lose track of unpushed/uncommitted changes, across multiple projects / clients. To get a handle on this, I wrote this script called git-dirty and put it at /usr/local/bin, with execute permissions. Feel free to change the argument after find to match where you keep your code projects. This version starts with your $HOME directory. If you mostly work with golang, you might set it to $HOME/go/src, or if you work at Amazon (as I do presently), you might find $HOME/workplace/[A-Za-z]*/. useful.

It finds all your git repos under your home directory. For each repo it:

  • checks to see if there are any pending changes.

  • If there are, it will:

    • output the full path of the repo

    • run git status --procelain, and ...

    • if you provide an argument to it, also run that command.

So you could use this script in combination with other commands to do some useful stuff:

  • git-dirty -- just show what you have that isn't committed, no action taken.

  • git-dirty git pull -- make sure you have the latest for each repo. I keep forgetting to git-pull after merging CRs in the web console.

  • git-dirty git reset --hard -- reset each repo back to whatever the latest local commit is.

  • git-dirty git clean -- remove untracked files from the working tree.

  • git-dirty zsh -- spawn into a shell into each "dirty" directory, where you can take any action you want interactively (i.e. git diff, git reset, make edits, commit/push your changes, or even use the Github CLI to create a PR. Just type exit from that shell, and git-dirty will find the next repo with uncommitted or unpushed changes, if any.

Comments welcome...

0
Subscribe to my newsletter

Read articles from Tim Bailey-Jones directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Tim Bailey-Jones
Tim Bailey-Jones

I am a developer living in the countryside east of Tampa Bay, Florida.