Git Developer Guide
How to check unpushed commits across all Git repos on macOS
The Command Line Solution
To check if a single Git repository has unpushed commits on its current branch, Git provides the upstream revision range syntax:
# Count commits ahead of upstream
git rev-list --count @{u}..HEAD 2>/dev/null
# Or view the short status line
git status -sb
To loop through all developer directories from the terminal, developers typically run a shell script:
for d in ~/Projects/*/; do
if [ -d "$d/.git" ]; then
ahead=$(git -C "$d" rev-list --count @{u}..HEAD 2>/dev/null || echo 0)
if [ "$ahead" -gt 0 ]; then
echo "$(basename "$d"): $ahead unpushed commit(s)"
fi
fi
done
Where the CLI script falls short
While this script works for simple setups, it suffers from several real-world limitations:
- No upstream configured: If you created a new feature branch locally and haven't run
git push -u origin <branch>yet,@{u}fails and the script silently skips it. - Spawns dozens of subprocesses: Shelling out to
git -Cfor dozens of repos takes seconds, spinning laptop fans and draining battery. - Manual execution: You have to remember to run the script every time before closing your laptop.
The easier way: GitMon
GitMon lives in your macOS menu bar and automatically parses your repositories' Git metadata in milliseconds without launching subprocesses.