0

I know this type of question has been asked everywhere, but none of the answers I find have helped. Typical problem:

[me@my_server]$ git merge origin development
Already up-to-date. Yeeah!
[me@my_server]$ git push origin development
To ssh://git@git.work.com:8022/my_project
 ! [rejected]        development -> development (non-fast-forward)
error: failed to push some refs to 'ssh://git@git.work.com:8022/my_url'
To prevent you from losing history, non-fast-forward updates were rejected
Merge the remote changes before pushing again.  See the 'Note about
fast-forwards' section of 'git push --help' for details.

What the push error is saying to me is that something is out of sync. That if my push were to be accepted, somewhere along the commit chain, the history of some commit will be lost. Instead of committing each change to the remote development branch in a linear fashion, accepting my push will force a non-linear change to occur.

The solution to that is to merge whatever is going on in development to my local branch, right? ...but my branch is already completely up-to-date with development. So if the 2 branches match except for my one change I'm trying to push (I just made a new file), then why is it rejecting? Where is this out-of-line non-fast-foward commit ?? Is there some log I can check to find the problem child and destroy it?

thanks

1 Answers1

1

You tried to push development without checking the state of origin/development, which you are probably out of sync with (hence the rejection). You probably want to git pull origin development (which will fetch the changes on origin/development and merge your stuff into that) and then git push origin development (which will push your new changes, merged on top of the latest stuff from origin, up to the server such that its fast forward-able merge able up there). You can also do a git pull --rebase if you want to do it that way instead of a merge.

DavidN
  • 7,947
  • 2
  • 17
  • 21
  • I had already tried that before and it showed i was up-to-date [me@server]$ git pull origin development From ssh://git.company/location * branch development -> FETCH_HEAD Already up-to-date. – Carl_Friedrich_Gauss Jul 11 '16 at 20:01
  • The "git pull --rebase " command worked just fine, but still getting exact same push error – Carl_Friedrich_Gauss Jul 11 '16 at 20:04
  • Can you do a git branch -avv and post results. It should show that you are one past origin there. – DavidN Jul 11 '16 at 20:09
  • You can also do a -f to force the push, but your probably dont want to do that and figure out whats going wrong, as that will probably orphan commits on the server and cause a loss of data there. – DavidN Jul 11 '16 at 20:10
  • You might try the following, copied from http://stackoverflow.com/questions/6897600/git-push-failed-non-fast-forward-updates-were-rejected The reason was, that my local branch had somehow lost the tracking to the remote counterpart. After git branch branch_name --set-upstream-to=origin/branch_name git pull and resolving the merging conflicts, I was able to push. – DavidN Jul 11 '16 at 20:12
  • Tried the -set-upstream and it didn't work ... also tried the git branch -av and `* myBranch 932a083 [origin/development: ahead 3] Merge branch 'development', remote branch 'origin' into myBranch development 2bc6ac3 [origin/development: behind 2] Merge branch 'donchef' into 'development'` – Carl_Friedrich_Gauss Jul 11 '16 at 20:36
  • Who knows what else might be messed up, but why not just try a new/clean clone, crate a bogus commit and push that to verify that you can push, then pull your other repo's changes into this new repo and try to push again (from the new repo). – DavidN Jul 11 '16 at 20:39
  • I've also already re-cloned the project (even tried on a totally different server) ... created a fresh branch, just created a file to commit, checked my git status, did a git pull just for the heck of it then went to push and then I get: `error: src refspec development does not match any. error: failed to push some refs to 'ssh://git@git.company:8022/project-cookbooks/project.git'` – Carl_Friedrich_Gauss Jul 11 '16 at 20:44
  • hmm, you did a git push origin development:development – DavidN Jul 11 '16 at 20:53
  • And try http://stackoverflow.com/questions/2765421/push-a-new-local-branch-to-a-remote-git-repository-and-track-it-too – DavidN Jul 11 '16 at 20:54