Egit rejected non-fast-forward

EclipseGithubEgit

Eclipse Problem Overview


I am getting this message while pushing to github repository. Can you tell me step by step procedure to fix it? I pushed only once and it was successful. But, when I updated a project and tried to push my second commit, it shows "master rejected non-fast-forward" and does not allow me to push. Please explain the procedure.

Eclipse Solutions


Solution 1 - Eclipse

I had this same problem and I was able to fix it. afk5min was right, the problem is the branch that you pulled code from has since changed on the remote repository. Per the standard git practices(http://git-scm.com/book/en/Git-Basics-Working-with-Remotes), you need to (now) merge those changes at the remote repository into your local changes before you can commit. This makes sense, this forces you to take other's changes and merge them into your code, ensuring that your code continues to function with the other changes in place.

Anyway, on to the steps.

  1. Configure the 'fetch' to fetch the branch you originally pulled from.

  2. Fetch the remote branch.

  3. Merge that remote branch onto your local branch.

  4. Commit the (merge) change in your local repo.

  5. Push the change to the remote repo.

In detail...

  1. In eclipse, open the view 'Git Repositories'.

  2. Ensure you see your local repository and can see the remote repository as a subfolder. In my version, it's called Remotes, and then I can see the remote project within that.

  3. Look for the green arrow pointing to the left, this is the 'fetch' arrow. Right click and select 'Configure Fetch'.

  4. You should see the URI, ensure that it points to the remote repository.

  5. Look in the ref mappings section of the pop-up. Mine was empty. This will indicate which remote references you want to fetch. Click 'Add'.

  6. Type in the branch name you need to fetch from the remote repository. Mine was 'master' (btw, a dropdown here would be great!!, for now, you have to type it). Continue through the pop-up, eventually clicking 'Finish'.

  7. Click 'Save and Fetch'. This will fetch that remote reference.

  8. Look in the 'Branches' folder of your local repository. You should now see that remote branch in the remote folder. Again, I see 'master'.

  9. Right-Click on the local branch in the 'Local' folder of 'Branches', which is named 'master'. Select 'Merge', and then select the remote branch, which is named 'origin/master'.

  10. Process through the merge.

  11. Commit any changes to your local repository.

  12. Push your changes to the remote repository.

  13. Go have a tasty beverage, congratulating yourself. Take the rest of the day off.

Solution 2 - Eclipse

In my case I chose the Force Update checkbox while pushing. It worked like a charm.

Solution 3 - Eclipse

In the meantime (while you were updating your project), other commits have been made to the 'master' branch. Therefore, you must pull those changes first to be able to push your changes.

Solution 4 - Eclipse

Applicable for Eclipse Luna + Eclipse Git 3.6.1

I,

  1. cloned git repository
  2. made some changes in source code
  3. staged changes from Git Staging View
  4. finally, commit and Push!

And I faced this issue with EGit and here is how I fixed it..

Yes, someone committed the changes before I commit my changes. So the changes are rejected. After this error, the changes gets actually committed to local repository. I did not want to just Pull the changes because I wanted to maintain linear history as pointed out in - https://stackoverflow.com/questions/15316601/in-what-cases-could-git-pull-be-harmful

So, I executed following steps

  1. from Git Repository perspective, right click on the concerned Git
    project
  2. select Fetch from Upstream - it fetches remote updates (refs and objects) but no updates are made locally. for more info refer https://stackoverflow.com/questions/292357/what-are-the-differences-between-git-pull-and-git-fetch
  3. select Rebase... - this open a popup, click on Preserve merges during rebase see why
    https://stackoverflow.com/questions/15915430/what-exactly-does-gits-rebase-preserve-merges-do-and-why
  4. click on Rebase button
  5. if there is/are a conflict(s), go to step 6 else step 11
  6. a Rebase Result popup would appear, just click on OK
  7. file comparator would open up, you need to modify left side file.
  8. once you are done with merging changes correctly, goto Git Staging view
  9. stage the changes. i.e. add to index
  10. on the same view, click on Rebase-> Continue. repeat 7 to 10 until all conflicts are resolved.
  11. from History view, select your commit row and select Push Commit
  12. select Rebase Commits of local....... checkbox and click next. refer why - https://stackoverflow.com/questions/19200561/git-rebase-onto-development-branch-from-upstream
  13. click on Finish

Note: if you have multiple local repository commits, you need to squash them in one commit to avoid multiple merges.

Solution 5 - Eclipse

Configure After pushing the code when you get a rejected message, click on configure and click Add spec as shown in this picture

Source ref and Destination ref Drop down and click on the ref/heads/yourbranchname and click on Add Spec again

enter image description here Make sure you select the force update

enter image description here Finally save and push the code to the repo

Solution 6 - Eclipse

Open git view :

1- select your project and choose merge 2- Select remote tracking 3- click ok

Git will merge the remote branch with local repository

4- then push

Solution 7 - Eclipse

This error means that remote repository has had other commits and has paced ahead of your local branch.
I try doing a git pull followed by a git push. If their are No conflicting changes, git pull gets the latest code to my local branch while keeping my changes intact.
Then a git push pushes my changes to the master branch.

Solution 8 - Eclipse

I have found that you must be on the latest commit of the git. So these are the steps to take:

  1. make sure you have not been working on the same files, otherwise you will run into a DITY_WORK_TREE error.
  2. pull the latest changes.
  3. commit your updates.

Hope this helps.

Solution 9 - Eclipse

In my case i forgot to pull the new changes from git

  1. Right click on the project Fetch From Upstream
  2. Right click on the project Pull
  3. Right click on the project Push to Upstream

Solution 10 - Eclipse

  1. Go in Github an create a repo for your new code.
  2. Use the new https or ssh url in Eclise when you are doing the push to upstream;

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJayView Question on Stackoverflow
Solution 1 - EclipseRobert BenderView Answer on Stackoverflow
Solution 2 - EclipseBSeitkazinView Answer on Stackoverflow
Solution 3 - Eclipseafk5minView Answer on Stackoverflow
Solution 4 - EclipseYogesh ManwareView Answer on Stackoverflow
Solution 5 - EclipseVineela ThonupunuriView Answer on Stackoverflow
Solution 6 - EclipsedafaliView Answer on Stackoverflow
Solution 7 - EclipsePushkinView Answer on Stackoverflow
Solution 8 - EclipseMighty ElementalView Answer on Stackoverflow
Solution 9 - EclipseD.RalucaView Answer on Stackoverflow
Solution 10 - Eclipseadrian filipescuView Answer on Stackoverflow