I have a bunch(10-15) of local git repositories somewhere on my filesystem, but all in the folder /data/
I want to find all/any folder that has uncommitted changes. How can I do that? Kind of like a recursive global git status
variant.
All the answers got it wrong I think. Any git command only works within the folder that's under git control. I need something to search for such folders.
So instead I wrote this script that does this:
#!/usr/bin/env ruby require 'find' require 'fileutils' #supply directory to search in as argument @pat = ARGV[0] (puts "directory argument required"; exit) unless @pat Dir.chdir(@pat) Find.find(@pat) do |path| if FileTest.directory?(path) Dir.chdir(path) resp = `git status 2>&1` unless resp =~ /fatal|nothing to commit \(working directory clean\)/i puts "#{'#'*10}\n#{Dir.pwd}#{'#'*10}\n#{resp}" Find.prune end Dir.chdir(@pat) end end
Adapted from this gist on how to print git status of all repositories under the current folder:
find . -type d -name '.git' | while read dir ; do sh -c "cd $dir/../ && echo -e \"\nGIT STATUS IN ${dir//\.git/}\" && git status -s" ; done
The find
command is your friend, along with some shell magic.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With