Last Updated: November 14, 2018
·
26.91K
· wkjagt

Git status on all repos in folder

Sometimes you have multiple git repositories in one folder. For example, in your own vendor folder when using Composer (for example vendor/cakemail). During development I keep the versions on @dev and work directly in them.

I was getting tired of cd-ing into each of them and doing a git status to see if I forgot to commit anything, so I put together this little oneliner that I will probably alias in my .bashrc:

find . -maxdepth 1 -mindepth 1 -type d -exec sh -c '(echo {} && cd {} && git status -s && echo)' \;

From the containing folder, execute this command and it will list the status of each repo in that folder.

How it works:

  • find . : to find everything in the current folder
  • -maxdepth 1 : so that it doesn't recurse into subdirs of the repos
  • -mindepth 1 : so that it skips the current directory (of depth 0)
  • -type d : only find directories
  • -exec sh -c : spawn a shell and give it a command
  • '(echo {} && cd {} && git status && echo)' : the command given to the shell
  • echo {} : echo the directory found by find
  • cd {} : cd into the directory found by find
  • git status -s : run the actual git status, with the -s (short) option
  • echo : echo an empty line, for readability
  • \; : semicolon to run shell for each of the found directories instead of passing them all to one shell as arguments

6 Responses
Add your response

Thanks!
I found it useful for my arduino sketchbook

over 1 year ago ·

Hi, I made some changes to make output color. Save this to shell script:

#!/bin/sh
find . -maxdepth 1 -mindepth 1 -type d -exec sh -c '(echo {} && cd {} && git -c color.status=always status && echo)' \; | less -R
over 1 year ago ·

Love this, great help for that nagging feeling of what have I not committed.

I tweaked this slightly to use git status -bs so that anything I've not pushed is shown. This makes the output a bit less clean but lets me feel safer about what changes only exist locally.

Any way to hide the folders which have nothing uncommitted and no local commits would be very cool. (I've also not considered multiple branches...)

over 1 year ago ·

Nice, you might want to check this similar project (with an infinite depth though):
https://github.com/brandon-rhodes/uncommitted

over 1 year ago ·

Thank you for providing this, as it got me going. I figured out a slightly simpler solution:
bash find $GIT_PARENT_PATH -name .git -execdir git status \;
How this works instead:

  • The $GIT_PARENT_PATH variable is wherever you hold your Git repositories. ** For example: "~/git/"
  • -name .git will find any file with the explicit name of '.git'
  • -execdir is similar to the -exec flag in 'find'. However it will run the following command from the directory that hosts the result. ** Example: if you have '~/git/foo/.git' as a result, then -execdir will run git status from '~/git/foo/'.
over 1 year ago ·

For those that want to make the provided command into an alias in your bashrc file, here is one way that worked for me.
alias yourAlias='find . -maxdepth 1 -mindepth 1 -type d -exec sh -c "echo {}; cd {}; git status -s; echo" \;'

over 1 year ago ·