Created
September 7, 2020 09:55
-
-
Save fqxp/05b19d02270a0c8a888f77c0b091089a to your computer and use it in GitHub Desktop.
`git info` command to show commits on current branch, whether a rebase to master is necessary and whether you need force-push
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 | |
CURRENT_BRANCH=$(git branch | grep '^\* ' | sed 's#..\(.*\)#\1#') | |
CURRENT_BRANCH_LENGTH=$(echo -n $CURRENT_BRANCH | wc -c) | |
echo | |
echo -e "\e[38;2;185;202;74mBranch »$CURRENT_BRANCH«" | |
echo -e "─────────$(printf '─%.0s' $(seq 1 $CURRENT_BRANCH_LENGTH))\e[0m" | |
echo | |
echo -e "\e[38;2;185;202;74m⯈ Commits on this branch\e[0m" | |
if [ "$(git l master..HEAD)" = "" ] ; then | |
echo -e "\e[38;2;180;180;180mNo commits on this branch yet\e[0m" | |
else | |
git l -n 9999 origin/master..HEAD | |
fi | |
echo | |
echo -e "\e[38;2;185;202;74m⯈ Changes on this branch\e[0m" | |
if [ "$(git status -s)" = "" ] ; then | |
echo "No changes." | |
else | |
git status -s | |
fi | |
if git log --oneline --decorate origin/${CURRENT_BRANCH}^..${CURRENT_BRANCH} | grep -q origin/${CURRENT_BRANCH} ; then | |
COUNT_COMMITS=$(git log --oneline origin/${CURRENT_BRANCH}..${CURRENT_BRANCH} | wc -l) | |
if [ "$COUNT_COMMITS" -eq 0 ] ; then | |
echo | |
echo -e "\e[38;2;185;202;74m✓ in sync with the origin branch.\e[0m" | |
else | |
echo | |
echo -e "\e[38;2;240;20;20m${COUNT_COMMITS} commits not pushed to origin yet.\e[0m" | |
fi | |
else | |
echo | |
echo -e "\e[38;2;240;20;20mOrigin and local branches have diverged — force-push necessary.\e[0m" | |
fi | |
echo | |
if git merge-tree $(git merge-base HEAD origin/master) origin/master HEAD | grep -qe '<<<<<<< HEAD' ; then | |
echo -e "\e[38;2;240;20;20m✗ conflicts with the origin/master branch.\e[0m" | |
else | |
echo -e "\e[38;2;185;202;74m✓ no conflicts with the origin/master branch.\e[0m" | |
fi | |
echo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment