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?
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):After
git pull --rebase 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:
git fetch remote git reset --hard remote/dev git pull origin
git checkout master git rebase dev git checkout dev git merge master
git branch –D master
git checkout dev git push remote dev