Rebase remote branch onto master while keeping the remote branch updated

23,015

Solution 1

to see more about rebase you can check this link or write git rebase --help at your terminal

To solve your problem there is a easy way, follow this steps:

git branch -D develop //this will remove your local develop repository
git fetch //update references 
git checkout develop //change to develop branch, but because you deleted, this command will also download the origin/develop
git rebase -p origin/master

at this step you can have some conflicts, so resolve them and git add FILES THAT HAD CONFLICTS and git rebase --continue

Now check if everything still working after rebase, if yes

git push -f origin develop

Solution 2

In your context, you will do

git rebase origin/master    
git rebase origin/master origin/develop

Official reference: At the beginning

      A---B---C topic
     /
D---E---F---G master

after do

git rebase master
git rebase master topic

we have

              A'--B'--C' topic
             /
D---E---F---G master

(Source: https://git-scm.com/docs/git-rebase)

Share:
23,015
Andrew
Author by

Andrew

Updated on August 05, 2020

Comments

  • Andrew
    Andrew over 3 years

    I am trying to rebase my remote branch onto master, but I want to keep the remote branch pointing to it's commits, just based at a different point in master.

    Here is my structure:

    A - B - C - D  (origin/master)
     \
      R - S - T (origin/develop)
    

    I would like:

    A  - B - C - D (origin/master) - R - S - T (origin/develop)
    

    Is such a rebase possible without some sort of merge?

  • Pe Dro
    Pe Dro about 4 years
    Does this imply that before rebasing, our local repo gets lost and the upstream repo is cloned into local?