git rebase three repositories

53 views Asked by At

I've got my local development branches (local/dev), the master branch of the original repository (origin/master) and my remote dev branch (remote/dev). When starting, local/dev and remote/dev are in sync.

Now I wanna fetch changes from origin/master, rebase it with my local/dev and push it to remote/dev.

So I've executed git pull --rebase origin master in my local/dev repository which seems to work fine.

But git status returns me this:

On branch dev
Your branch and 'remote/dev' have diverged,
and have 8 and 5 different commits each, respectively.
  (use "git pull" to merge the remote branch into yours)
nothing to commit, working tree clean

and git push remote dev will result in

To github.com:PascalTurbo/dev.git
 ! [rejected]        logger -> logger (non-fast-forward)
error: failed to push some refs to '[email protected]:PascalTurbo/dev.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

How can I fix this?

1

There are 1 answers

0
Marina Liu On BEST ANSWER

Actually it’s not work fine when you execute git pull --rebase origin master. Let’s illustrate by below graphs (with two repositories-local and origin, this also used for three repositories):

  A---B---C  local/dev, origin/dev
 /         
D---E---F---G  origin/master

After git pull --rebase origin master

  A---B---C  origin/dev
 /         
D---E---F---G---A’---B’---C’  local/dev
            |
       origin/master

So it’s really diverged local/dev and remote/dev, and it’s not want you really want. There is a way for you to realize your requirement:

  1. Recover local repo as remote.

git fetch remote git reset --hard remote/dev git pull origin

  1. Put origin/master changes on the top of local/dev branch.

git checkout master git rebase dev git checkout dev git merge master

  1. Remove unused changes. git branch –D master
  2. Push changes on local/dev branch to remote/dev.

git checkout dev git push remote dev