-
-
Save dbu/2843660 to your computer and use it in GitHub Desktop.
#!/usr/bin/php | |
<?php | |
$repos = array(); | |
exec('find -type d -name .git | sed -e "s/\.git//"', $repos); | |
foreach ($repos as $repo) { | |
$status = shell_exec("cd $repo && git status"); | |
if (false == strpos($status, 'nothing to commit (working directory clean)')) { | |
echo "$repo\n" . str_repeat('-', strlen($repo)) . "\n$status\n\n"; | |
} | |
} |
@glittle , awesome,
If you want to check all git folders in "C:\some-folder" run the following (1 level, runs faster)
for /f "tokens=*" %a in ('dir /ad /b') do (echo off & cd "c:\\some-folder\\%~a" & cd & git status -s)
You don't need to search everything. Do:
find . -maxdepth 2 -name .git -type d -exec sh -c "cd {}/..;git status" \;
find . -name '.git' | while read repo; do echo -e "\n$(dirname $repo)"; git --git-dir=$repo --work-tree=$(dirname $repo) status -s -b; done
ahh very good, thank you @Gabriel-p!
//
replaces anywhere,%
replaces only a match on the end of the string, so%
is to be used here.fixed version of the script:
#!/usr/bin/env bash # Recursive `git status` (including sub-modules) set -e status_ops="$*" find . -name '.git' \ | while read -r repo do repo=${repo%".git"} (git -C "$repo" status -s \ | grep -q -v "^\$" \ && echo -e "\n\033[1m${repo}\033[m" \ && git -C "$repo" status $status_ops) \ || true done... and as one-liner:
find . -name '.git' | while read -r repo ; do repo=${repo%".git"}; (git -C "$repo" status -s | grep -q -v "^\$" && echo -e "\n\033[1m${repo}\033[m" && git -C "$repo" status -s) || true; done
I discovered from here that if you want to run that script as a git command without making an alias, you have to:
- Name your script: "git-command"
- Make your script executable
- Move your script to a directory that's in your PATH
E.g.:
If your PATH contains ~/.local/bin/ and you named your script "git-str" then:
chmod +x git-str && mv git-str ~/.local/bin/
Now you can run: git str.
To any Linux novice, beware of what script you make executable, as it may be dangerous for your system.
(The
echo off
helps the output look less cluttered but may wreck your prompt. If so, exit the window when done.)
after the command is done, typing echo on
will bring back the prompt.
This one (1) produces a slim output, and (2) starts printing the results instantly (you don't have to wait it to finish to see the final output):
find . -maxdepth 2 -name .git -type d -exec sh -c "cd {}/..; pwd; git status -s" \;
For Windows users... try this in the root folder above the folders to search:
(The
echo off
helps the output look less cluttered but may wreck your prompt. If so, exit the window when done.)