Created
July 17, 2019 14:02
-
-
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
This file contains hidden or 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 | |
| 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