Created
September 28, 2016 13:16
-
-
Save MitMaro/28536c0b3de56ba5ce006e90088643af to your computer and use it in GitHub Desktop.
Git Show Branches
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
| #!/bin/bash | |
| if [[ "$#" -ne 1 ]]; then | |
| echo "usage: git show-merged <remote>" | |
| echo | |
| exit 1 | |
| fi | |
| remote="$1" | |
| if ! git ls-remote --exit-code "$remote" &> /dev/null; then | |
| echo "The remote, $remote, does not exist" | |
| echo | |
| exit 1 | |
| fi | |
| tab=$'\t' | |
| # color codes added to headers to ensure alignment | |
| output=$(git log -n1 --pretty="Branch ${tab} Hash%Cgreen%Creset ${tab} Age ${tab} Author%Cblue%Creset ${tab} B%Cred%Creset ${tab} A%Cgreen%Creset ${tab} Upstream" master)$'\n' | |
| #output="Branch ${tab} Hash${gitGreen}${gitReset} ${tab} Age ${tab} Author${gitBlue}${gitReset} ${tab} B${gitRed}${gitReset} ${tab} A${gitGreen}${gitReset} ${tab} Upstream"$'\n' | |
| while read branch; do | |
| upstream=$(git rev-parse --abbrev-ref "$branch@{upstream}" 2>/dev/null) | |
| stats=$(git rev-list --left-right --count "$remote/master...$branch") | |
| behind=$(echo "$stats" | cut -f1) | |
| ahead=$(echo "$stats" | cut -f2) | |
| output+=$(git log -n1 --pretty="${branch} ${tab} %Cgreen%h%Creset ${tab} %ar ${tab} (%Cblue%aN%Creset) ${tab} %Cred${behind}%Creset ${tab} %Cgreen${ahead}%Creset ${tab} ${upstream}" $branch)$'\n' | |
| done < <(git for-each-ref --format='%(refname:short)' refs/heads/*) | |
| echo "$output" | column -xts "$tab" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment