git status on multiple repos

Show_status
git status is now better

Often a lot of the work I do is on services. This means that, in any given day, I’ll perhaps be working on one or more repos. As is the way of git, I commit often to the local working branch and they push to the master at the end of the day, or whenever I’ve got feature, or patch of fix or whatever that needs to go back upstream. First thing in the morning, I’ll also do a pull for each repo I’m going to work on, including dependent repos.

If you’ve got a lot or repos, this quickly gets tedious to cd into each directory, run git status, then git push or git pull, cd back out, then into the next directory, etc etc.

So, I wrote a wee python script called ‘show_status’

Usage: show_status [options]

Show Status is awesome. If you tell it a directory to look in, it'll scan
through all the sub dirs looking for a .git directory. When it finds one it'll
look to see if there are any changes and let you know. It can also push and
pull to/from a remote location (like github.com) (but only if there are no
changes.) Contact mike@mikepearce.net for any support.

Options:
  -h, --help            show this help message and exit
  -d DIRNAME, --dir=DIRNAME
                        The directory to parse sub dirs from
  -v, --verbose         Show the full detail of git status
  -r REMOTE, --remote=REMOTE
                        Push to the master (remotename:branchname)
  -p PULL, --pull=PULL  Pull from the master (remotename:branchname)

Just running ‘show_status’ will always run a non-verbose check on any sub dirs in your current dir, so:

%> show_status
-- Starting git status...
Scanning sub directories of /home/sites/
--/home/sites/gitstatus        : No Changes
--/home/sites/projectone    : No Changes
--/home/sites/project2        : No Changes
Done

You can also pass in a directory that you want to use, this is useful if you wanted to use it in other scripts, or if you’re not in a root directory:

%> show_status -d/home/sites

You can add a pull request, which will pull from a remote master. It’s important to note that it’ll only pull from a remote master if there are no local changes waiting to be committed. This is to force you to manage your merges carefully.

%> show_status -pmikepearce:master

Finally, you can do push requests as well, again, this will only work on repos where there is nothing waiting to be commited:

%> show_status -rmikepearce:master

You can grab the whole thing on github (Git Status), or just clone/fork here: git@github.com:MikePearce/Git-Status.git

Advertisements

3 thoughts on “git status on multiple repos

  1. Thanks a lot for this. Exactly what I was looking for. Have ~200 git repos containing data/analysis scripts from experiments and I like to check that I haven’t got any uncommitted changes.

  2. a shell alternative:

    find . -type d -depth 1 -exec sh -c ‘echo “\n \x1B[0;33m CHECKING STATUS IN {} \x1B[0m \n”‘ \; -exec git -C {} status \;

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s