views:

13

answers:

1

Hi to all,

Issue

I merged a branch in a master not updated at last commit.

What I do

I merged a branch in master

git merged BRANCHNAME

Conflicts

Automatic merge failed; fix conflicts and then commit the result.

git commit -a -m "Resolved conflicts while merging email-fix branch"

Then I tried to push all to origin master, but it says:

 ! [rejected]        master -> master (non-fast-forward)

How can I solve this problem?

+1  A: 

You can do:

  • a git pull --rebase, in order to replay your merge on top of an up-to-date master branch
  • then a git push (which should go smoothly)

The other alternative would be to force the push, which would mean loosing the recent history on the remote master: not a very good idea.

Both alternatives are presented in the Git FAQ, although only a simple git pull is advocated.
The git push man page mentions the git pull --rebase:

For example, suppose you and somebody else started at the same commit X, and you built a history leading to commit B while the other person built a history leading to commit A. The history looks like this:

      B
     /
 ---X---A

Alternatively, you can rebase your change between X and B on top of A, with "git pull --rebase", and push the result back. The rebase will create a new commit D that builds the change between X and B on top of A.

      B   D
     /   /
 ---X---A

Again, updating A with this commit will fast-forward and your push will be accepted.

VonC
Thank you for your reply. I solved the problem ;)
zetareticoli