Skip to content

Instantly share code, notes, and snippets.

@ivanov
Created November 7, 2013 20:16
Show Gist options
  • Save ivanov/7361145 to your computer and use it in GitHub Desktop.
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.
#!/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