Created
December 25, 2022 09:27
-
-
Save overengineer/b5291fdf107f23dbf2c953821e97ea77 to your computer and use it in GitHub Desktop.
Git Branches
This file contains 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 | |
set -euo pipefail | |
MSYS_NO_PATHCONV=0 | |
git clean -ffd | |
git reset --hard 2>/dev/null 1>/dev/null | |
git checkout dev | |
# git fsck && git prune && git gc | |
git for-each-ref --format='%(refname:short)' --sort=-committerdate refs/heads/ | while read -r branch; do | |
printf '%s' "$branch" | |
printf '\t' | |
printf "%s" "$(git log -1 --format=%cd | sed -E -e ':a' -e '/./,$!d;/^\n*$/{$d;N;};/\n$/ba')" | |
git checkout "$branch" 2>/dev/null 1>/dev/null | |
RESULT=$(git diff --quiet dev 2>/dev/null 1>/dev/null && echo true || echo false) | |
printf '\t' | |
if [ "$RESULT" == false ]; then | |
RESULT=$(git merge --no-commit --no-ff dev 2>/dev/null 1>/dev/null && echo false || echo true) | |
if [ "$RESULT" == true ]; then | |
printf "conflict" | |
else | |
printf "merges" | |
fi | |
git reset --hard 2>/dev/null 1>/dev/null | |
else | |
printf "dev" | |
fi | |
printf '\t' | |
RESULT=$(git rev-parse --abbrev-ref --symbolic-full-name '@{u}' 2>/dev/null 1>/dev/null && echo false || echo true) | |
if [ "$RESULT" == false ]; then | |
printf "upstream" | |
else | |
printf "local" | |
fi | |
# git rev-list --left-right "HEAD...origin/${branch}" -- 2>/dev/null >/tmp/git_upstream_status_delta || true | |
# LEFT_AHEAD=$(grep -c '^<' /tmp/git_upstream_status_delta || echo 0) | |
# RIGHT_AHEAD=$(grep -c '^>' /tmp/git_upstream_status_delta || echo 0) | |
# printf '\t' | |
# if [ "$LEFT_AHEAD" == "0" ]; then | |
# if [ "$RIGHT_AHEAD" == "0" ]; then | |
# printf "sync" | |
# else | |
# printf "behind" | |
# fi | |
# else | |
# if [ "$RIGHT_AHEAD" == "0" ]; then | |
# printf "ahead" | |
# else | |
# printf "outofsync" | |
# fi | |
# fi | |
printf '\n' | |
done | column -ts $'\t' | |
git reset --hard 2>/dev/null 1>/dev/null | |
git checkout dev |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment