How to Perform a Simple Rebase the Right Way
2022-04-25Here is a simple rebasing strategy you should use to keep your work up to date with new changes that have been introduced into another branch.
TL;DR - Click Here to skip to the actual git commands you're looking for
Let's say you are in this situation. First, you've started on your master
branch:
Then you create a new branch called user_story
and add some commits:
And then you find out that someone else has added commits to master
that you need!
To get these new commits onto your user_story
branch, you have a couple of options. One of them is to simply "rebase" your user_story
branch on top of master
with the command git rebase master
:
Note that your local copy of master
will need to be up-to-date for this to work!
If you know that someone has added commits to master
, but you don't see them locally, then the following set of commands is a fool-proof way of ensuring you're rebasing on top of the right commits:
Assuming your remote is named origin
:
git fetch origin
git rebase origin/master
git fetch
will pull down any changes from the specified remote (origin
in this case) git rebase origin/master
will rebase your changes on top of whatever commit the origin
remote is reporting that its master
is pointing at.
I hope that helps! Stay tuned for more Git tips in the future!