How to rebase local branch onto remote master How to rebase local branch onto remote master git git

How to rebase local branch onto remote master


First fetch the new master from the upstream repository, then rebase your work branch on that:

git fetch origin            # Updates origin/mastergit rebase origin/master    # Rebases current branch onto origin/master

Update: Please see Paul Draper's answer for a more concise way to do the same - recent Git versions provide a simpler way to do the equivalent of the above two commands.


git pull --rebase origin master


After committing changes to your branch, checkout master and pull it to get its latest changes from the repo:

git checkout mastergit pull origin master

Then checkout your branch and rebase your changes on master:

git checkout RBgit rebase master

...or last two commands in one line:

git rebase master RB

When trying to push back to origin/RB, you'll probably get an error; if you're the only one working on RB, you can force push:

git push --force origin RB

...or as follows if you have git configured appropriately:

git push -f