Skip to content

Instantly share code, notes, and snippets.

@nicwolff
Created August 21, 2012 15:01
Show Gist options
  • Save nicwolff/3416281 to your computer and use it in GitHub Desktop.
Save nicwolff/3416281 to your computer and use it in GitHub Desktop.
Git alias to rebase master branch on origin and rebase current branch on it
[alias]
up = ! git stash && git checkout master && (git pull --rebase | grep 'up to date' && git checkout '@{-1}' || git checkout '@{-2}' ) && git rebase master && git stash pop
@nicwolff
Copy link
Author

The tricky part is that if the pull --rebase of master on origin updates master with any commits, then the "previous branch" in reflog is "master" and we have to go back 2 branches.

@nicwolff
Copy link
Author

Added "git stash" and "git stash apply"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment