Skip to content

Instantly share code, notes, and snippets.

@johnghill
Created December 10, 2016 18:40
Show Gist options
  • Save johnghill/e7330623d931d4fd533be3a161f6785c to your computer and use it in GitHub Desktop.
Save johnghill/e7330623d931d4fd533be3a161f6785c to your computer and use it in GitHub Desktop.
[git] Assert local HEAD and remote ORIGIN on same commit
#!/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