Last active
December 16, 2025 22:37
-
-
Save cgoldberg/35715354ce7674c44f67a8b70f9901d7 to your computer and use it in GitHub Desktop.
Bash/Git - show local branches and how far ahead/behind they are from remote/origin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| # show local branches and how far ahead/behind they are from remote/origin | |
| git fetch origin | |
| for branch in $(git branch --format='%(refname:short)'); do | |
| remote_branch="origin/$branch" | |
| if git show-ref --verify --quiet refs/remotes/$remote_branch; then | |
| ahead=$(git rev-list --count $remote_branch..$branch) | |
| behind=$(git rev-list --count $branch..$remote_branch) | |
| echo "$branch -> $remote_branch : ahead $ahead, behind $behind" | |
| else | |
| echo "$branch -> $remote_branch : does not exist on remote" | |
| fi | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment