grmruq
Last Updated: January 05, 2018
·
7.189K
· wkjagt
Ccc9abdf9963f3452808cff0e77679a1

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
Say Thanks
Respond

3 Responses
Add your response

21157
None

Thanks!
I found it useful for my arduino sketchbook

over 1 year ago ·
21405
None

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

over 1 year ago ·
29551

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
about 1 month ago ·
Filed Under