Skip to content

Instantly share code, notes, and snippets.

@mfehr
Last active June 18, 2018 13:56
Show Gist options
  • Save mfehr/1217a05b97bc944339dee260331e01fd to your computer and use it in GitHub Desktop.
Save mfehr/1217a05b97bc944339dee260331e01fd to your computer and use it in GitHub Desktop.
Show all branches and whether they are up to date on the remote
#!/bin/bash
git fetch --quiet
message="Does not exist on remote!"
all_remote_branches=$(git branch -r)
echo -e "\n\e[1m remote\tlocal\tbranch name\e[0m"
git branch | while read line ; do
output_line=""
branch_name=${line//"* "}
if [[ $all_remote_branches =~ .*origin\/$branch_name[[:space:]]+.* ]]; then
branch_status=$(git rev-list --left-right --count origin/${branch_name}...${branch_name})
output_line=" $branch_status\t"
if [[ $branch_status =~ .*0[[:space:]]+0.* ]]; then
echo -e "$output_line\e[32m${branch_name}\e[0m"
elif [[ $branch_status =~ .*[0-9][[:space:]]+0.* ]]; then
echo -e "$output_line\e[33m${branch_name}\e[0m"
else
echo -e "$output_line\e[31m${branch_name}\e[0m"
fi
else
echo -e " -\t-\t\e[31m${branch_name}\e[0m -> $message"
fi
done
@floriantschopp
Copy link

#!/bin/bash

@mfehr
Copy link
Author

mfehr commented Jun 18, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment