Skip to content

Instantly share code, notes, and snippets.

@aubricus
Last active October 6, 2015 18:13
Show Gist options
  • Save aubricus/b4099d1e62c5cfbcdc77 to your computer and use it in GitHub Desktop.
Save aubricus/b4099d1e62c5cfbcdc77 to your computer and use it in GitHub Desktop.
Rebase a local branch who's upstream has been rebased.
# Thanks to:
# http://stackoverflow.com/a/20423029 (recover rebased upstream)
# http://stackoverflow.com/a/11868440 (get current branch name)
# Note:
# Be sure to checkout the branch you wish to re-sync / recover
# change this to desired upstream
upstream_branch=upstream/environment-detail
# just stores current branch name for later
current_branch=$(git symbolic-ref --short HEAD)
# finds common commit between upstream and current branch
fork_point=$(git merge-base --fork-point $upstream_branch $current_branch)
# perform rebase
git rebase --onto $upstream_branch $fork_point $current_branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment