Be sure you check all branches
Unpushed changes can exist in branches other than the checked-out branch. There can also be more than one upstream per branch.
Zero in on relevant info
This approach takes its lead from other answers, which are very helpful starting points, and subs out a few details.
find / -name "*.git" -type d -print0 | xargs -0 -L 1 -I% sh -c "cd %/..; pwd; git status -suno; git branch -vvv 2>/dev/null" > local_repos.txt
The above one-liner writes to a file called local_repos.txt, which is the easiest way to read the output. It
- lists all branches, marking the checked-out branch with an asterisk
- clarifies when repo HEAD is detached
- shows tracked files with uncommitted changes
- distinguishes which branches have upstreams and which do not
- counts the commits of each branch that is ahead/behind its upstreams
- gives the most recent sha & commit message on each branch
Like the other solutions, it also lists the path to each repo. Unlike the other solutions, it does not break out a list of references to unpushed commits on the checked-out branch.
Example output
/dir-with-repo-1
main d96c7fcd [origin/main: behind 3] update abcd
* staging f938e4aa [origin/staging: ahead 2, behind 6] tweak workspace layout
/dir-with-repo-2
* dev 8b9cec2b [origin/dev] Merge branch 'feature/35-featurename' into 'dev'
main b96d6fcd [origin/main: behind 4] update efgh
/dir-with-repo-3
* hotfix 239f95dc [origin/hotfix] update ijkl
main 4c92eaa7 [origin/main: behind 7] update klmn
/dir-with-repo-4
M composer.json
M composer.lock
* main 0d2050c add opqr
/dir-with-repo-5
* (HEAD detached at d3286d57) d3286d57 fix(FunctionComment): Add support for hijk
1.2.3 d3286d57 [origin/1.2.3] Add support for hijk