Skip to content

Instantly share code, notes, and snippets.

@Jmainguy
Created July 17, 2019 14:02
Show Gist options
  • Save Jmainguy/69779ba74f050fa5085413a708a3a465 to your computer and use it in GitHub Desktop.
Save Jmainguy/69779ba74f050fa5085413a708a3a465 to your computer and use it in GitHub Desktop.
git-update-heads for when you make a git mistake and want latest copy
#!/bin/bash
function has-branch {
branch=$1
git branch --no-color | grep -q " ${branch}$"
}
thisbranch() {
git branch --no-color | sed -r -n "s/(\* )(.*)/\2/p"
}
greset() {
git reset --hard origin/${1}
}
resethead() {
if has-branch "${1}"; then
git checkout "${1}"
git fetch
greset "${1}"
fi
}
ONBRANCH=`thisbranch`
resethead $ONBRANCH
resethead master
git checkout $ONBRANCH
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment