2

I'm trying to push my master branch to my production branch.

Normally when I do changes on my Ubuntu computer I push to master by:

git add . git commit -m "message" git push 

And everything works fine. Then I simply do:

git push origin master:production 

And everything works fine. But now for some reason when I do the 'git push origin master:production' in Terminal I get the message:

To [email protected]:Username1/myapp.git ! [rejected] master -> production (non-fast-forward) error: failed to push some refs to '[email protected]:Username1/myapp.git' To prevent you from losing history, non-fast-forward updates were rejected Merge the remote changes (e.g. 'git pull') before pushing again. See the 'Note about fast-forwards' section of 'git push --help' for details. mypc@ubuntu:~/myapp$ 

How can I fix this irritating problem that has mysteriously arisen? I tried 'git pull origin master', as suggested in the message and elsewhere in my research, but all I get in Terminal is 'everything up to date' and the problem reoccurs when I try it again. Thanks.

4
  • 1
    you need to pull the correct branch your pulling master instead of production by the look of it Commented Jul 19, 2013 at 8:51
  • Thanks. Although I don't know how my production branch can be different, as the direction is always local->master->production. When I do 'git pull origin production' I get 'CONFLICT (content): Merge conflict in config/oauth.yml Automatic merge failed; fix conflicts and then commit the result.'What is the best way to deal with this? Maybe delete offending oauth.yml from production branch in github and push again as normal? Commented Jul 19, 2013 at 9:10
  • 1
    Look at the conflicts ? git mergetool will help you merge the changes which conflict Commented Jul 19, 2013 at 9:25
  • cheers, looking into it now. Commented Jul 19, 2013 at 9:29

3 Answers 3

2

Somebody has already committed to production branch.

As @user1281385 said you should

git pull origin master:prooduction or better before review changes on production branch in other way.

try git help pull to read more.

Sign up to request clarification or add additional context in comments.

3 Comments

Don't use refspecs (foo:bar) with git fetch/pull unless you know very, very well what that does. In this case, it tries to overwrite your local production branch with the contents from the remote master branch. There are safeguards to prevent actual loss of data, but still...
Please correct this answer with command that would go for any user.
What I'd do is this: git fetch; then look at master and origin/production to see what changes I'm going to get, then finally git merge origin/production (while I'm on master).
1

remote changes are done on the repository. as the error messages says:

Merge the remote changes (e.g. 'git pull') before pushing again. 

pull first, then push.

Comments

1

You can try git push origin --force master:production if you have done a reset between this push and the last one.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.