I have a cloned project from a master branch from remote repository remote_repo
. I create a new branch and I commit to that branch. Other programmers pushed to remote_repo
to the master branch.
I now need to rebase my local branch RB
onto remote_repo
's master
branch.
How to do this? What commands to type to a terminal?
From merge to rebaseCreate a new “feature” branch called `my-new-feature` from a base branch, such as `master` or `develop` Do some work and commit the changes to the feature branch. Push the feature branch to the centralized shared repo. Open a new Pull Request for `my-new-feature`
To rebase a branch, checkout the branch and then rebase it on top of another branch. Important: After the rebase, the applied commits will have a different hash. You should not rebase commits you have already pushed to a remote host.
First fetch the new master from the upstream repository, then rebase your work branch on that:
git fetch origin # Updates origin/master git 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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With