Skip to content

Instantly share code, notes, and snippets.

@AlecTaylor
Forked from anonymous/update_git.bash
Created September 29, 2017 05:24
Show Gist options
  • Save AlecTaylor/6e2a5adc8e170fde45850589551fad51 to your computer and use it in GitHub Desktop.
Save AlecTaylor/6e2a5adc8e170fde45850589551fad51 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# Returns true if git needs to be updated; false otherwise
function update_git() {
pushd "$1"
git remote update
if [ $(git rev-parse HEAD) = $(git ls-remote $(git rev-parse --abbrev-ref @{u} | \
sed 's/\// /g') | cut -f1) ]; then
res=0;
else
res=1;
fi
if [ "$res" = 1 ]; then
git reset --hard HEAD
git clean -f -d
fi
popd
return "$res"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment