Created
December 10, 2016 18:40
-
-
Save johnghill/e7330623d931d4fd533be3a161f6785c to your computer and use it in GitHub Desktop.
[git] Assert local HEAD and remote ORIGIN on same commit
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 | |
# | |
# Asserts that local HEAD and remote ORIGIN are at same commit i.e. avoids a mess | |
# Based on CodeGnome @ http://stackoverflow.com/a/11181747 | |
# | |
remote=$( | |
git ls-remote -h origin master | | |
awk '{print $1}' | |
) | |
local=$(git rev-parse HEAD) | |
printf "Local : %s\nRemote: %s\n" $local $remote | |
if [[ $local == $remote ]]; then | |
echo -e "\033[0;32mCommits match.\033[0m" | |
else | |
echo -e "\033[0;31mCommits don't match.\033[0m" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment