Reputation: 3656
I really like how the Github /branches page lists the branches and a column that indicates the number of commits ahead or behind master for a branch.
Is there a way to see this information in the console/cli?
Edit: This solution shows how to get the commits ahead/behind for a single branch. But how could I do that for all local branches?
Upvotes: 6
Views: 939
Reputation: 1
I needed something like this as an alias, so converted it is:
alias gitbs='git for-each-ref refs/heads/ --format='\''%(refname:short)'\'' | while read branch; do echo -n "$branch: " ; git rev-list --left-right --count master..$branch ; done'
Upvotes: 0
Reputation: 94502
git for-each-ref refs/heads/ --format='%(refname:short)' |
while read branch; do
echo -n "$branch: "
git rev-list --left-right --count master..$branch
done
Docs:
https://git-scm.com/docs/git-for-each-ref
https://git-scm.com/docs/git-rev-list
Upvotes: 7