Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to rebase local branch onto remote master

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?

like image 390
Damir Avatar asked Oct 28 '11 12:10

Damir


People also ask

How do I rebase a branch to a master?

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`

How do I rebase a local branch to another branch?

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.


2 Answers

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.

like image 90
Frerich Raabe Avatar answered Nov 18 '22 17:11

Frerich Raabe


git pull --rebase origin master 
like image 23
Paul Draper Avatar answered Nov 18 '22 17:11

Paul Draper