Created
November 7, 2013 20:16
-
-
Save ivanov/7361145 to your computer and use it in GitHub Desktop.
Your local checkout of a branch, and the remote branch it tracks are out of sync. You want to check it out again, discarding your version of the branch.
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 | |
# git-recheckout: git reset to the upstream branch | |
# | |
# Your local checkout of a branch, and the remote branch it tracks are out of | |
# sync. You want to check it out again, discarding your version of the branch. | |
# | |
# Because you need to know the remotename/branchname string to reset to | |
# | |
# 1. get the remotename/the-branch combination | |
# 2. git reset remotename/the-branch | |
# | |
# NOTE: If you ever do this accidentally, you can still get your work back by | |
# finding the appropriate commits via git-reflog. | |
# | |
remote_branch=`git status -b -uno --porcelain | head -1 | cut -f2 -d\ |cut -f4 -d.` | |
git reset $@ "$remote_branch" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment