15

I've run into a problem with my origin/branch being out of sync with my local branch, see below

My commit history

When I try to PUSH from my local "staging" branch to the origin/staging branch I get the "rejected - non-fast-forward" error.

I use Eclipse with the EGit module on a windows PC.

From another post here I see that I can resolve my issue with the "git push --force origin staging" to over-ride the origin/staging branch with my local branch.

However, I don't see that option with EGit, and I don't see how to open a console in EGit to do this?

Does anyone know if I can do this within EGit?

OK - fixed my own issue. It appears I had issues with Commits that had not been Pushed back to origin/staging. Found an overview here on using the "git reset XXX : without --hard" which resets the branch marker, but keeps the local changes for later recommits.

Thanks, Jason

Community
  • 1
  • 1
Jason
  • 393
  • 1
  • 5
  • 18

3 Answers3

31

I have just come across a similar issue and here's what I did:

  1. Team -> Push Branch <name of branch> ...
  2. Force overwrite of branch on remote if it exists and has diverged
dan carter
  • 4,158
  • 1
  • 33
  • 34
Tomek Samcik
  • 526
  • 4
  • 7
5

Are you sure you want to overwrite the remote branch and lose all those commits?

If there are commits on the remote branch that aren't in your local branch, you should merge them into your local branch before pushing

For example, whilst on your local staging branch:

git merge origin/staging

However, if you're sure, then I suggest you check the "Force update" option on the push refspec.

It's a little complicated to get to, but the EGit user guide explains it when discussing Pushing to other Repositories, and the specific section that mentioned the "Force Update" option is in the section on Push Ref Specifications

Edit 0: With respect to your failed merge, I've not yet encountered a merge that fails outright rather than result in a conflict, and it appears it may be a known issue

chrisbunney
  • 5,819
  • 7
  • 48
  • 67
0

If you do a force push, you will lose everything added to origin/staging after fixing the missing Location: string in the header, and you'll break everyone else's branches. I don't think that's what you want. You probably want to do a pull first, then the push will work just fine.

Karl Bielefeldt
  • 47,314
  • 10
  • 60
  • 94
  • Worth noting that pull will try to auto-merge, and if it succeeds, then everything will work just fine. If not, user has to merge himself, commit that and then it should be ok. – eis Sep 06 '12 at 14:34
  • 1
    Merge fail msg: Merge of revisions 4092d67bbfda43148cc078674f2f2738720caade, 5df2879b3ecf2b7d0e1d0209a1f7862ce6f5aa9b with base 8643195cd4a8391497469a92d627ef5cf8480e13 using strategy resolve resulted in: Failed. – Jason Sep 06 '12 at 14:40
  • If you are unable to merge the remote branch into your local, as your comments indicate, I'd suggest that's your actual issue and a new question to address that would be appropriate, but it might be a bug in EGit. – chrisbunney Sep 06 '12 at 15:03