A trick I've used a few times is to write a shell wrapper function around git
. Assuming you're using Bash (it's similar for other shells), add the following to your ~/.bashrc
:
git () {
if [[ $1 == status ]]
then
# User has run git status.
#
# Run git status for this folder. The "command" part means we actually
# call git, not this function again.
command git status .
# And now do the same for every subfolder that contains a .git
# directory.
#
# Use find for the loop so we don't need to worry about people doing
# silly things like putting spaces in directory names (which we would
# need to worry about with things like `for i in $(ls)`). This also
# makes it easier to recurse into all subdirectories, not just the
# immediate ones.
#
# Note also that find doesn't run inside this shell environment, so we
# don't need to worry about prepending "command".
find * -type d -name .git -execdir git status . \;
else
# Not git status. Just run the command as provided.
command git "$@"
fi
}
Now when you run git status
, it'll actually run git status
for the current folder and in any subfolder that contains its own .git
folder.
Alternatively, you could make this into a new command, either by writing a script as Chronial suggests, or by putting it into a Git alias. To do the latter, run something like the following command:
git config --global alias.full-status '!cd ${GIT_PREFIX:-.}; git status .; find * -type d -name .git -execdir git status . \;'
Then you'll be able to run git full-status
to do the same thing.
(The cd ${GIT_PREFIX:-.}
part is there to return you to whichever directory you ran the command from; Git aliases by default run from the root of the repository. The rest is as for the function solution above.)