[eclipse] Egit rejected non-fast-forward

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.

This question is related to eclipse github egit

The answer is


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 - 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 What is the difference between 'git pull' and 'git fetch'?
  3. select Rebase... - this open a popup, click on Preserve merges during rebase see why
    What exactly does git's "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 - 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.


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


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


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.


  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;

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


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.


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.


Examples related to eclipse

How do I get the command-line for an Eclipse run configuration? My eclipse won't open, i download the bundle pack it keeps saying error log strange error in my Animation Drawable How to uninstall Eclipse? How to resolve Unable to load authentication plugin 'caching_sha2_password' issue Class has been compiled by a more recent version of the Java Environment Eclipse No tests found using JUnit 5 caused by NoClassDefFoundError for LauncherFactory How to downgrade Java from 9 to 8 on a MACOS. Eclipse is not running with Java 9 "The POM for ... is missing, no dependency information available" even though it exists in Maven Repository The origin server did not find a current representation for the target resource or is not willing to disclose that one exists. on deploying to tomcat

Examples related to github

Does the target directory for a git clone have to match the repo name? Issue in installing php7.2-mcrypt How can I switch to another branch in git? How to draw checkbox or tick mark in GitHub Markdown table? How to add a new project to Github using VS Code git clone error: RPC failed; curl 56 OpenSSL SSL_read: SSL_ERROR_SYSCALL, errno 10054 How to add empty spaces into MD markdown readme on GitHub? key_load_public: invalid format git - remote add origin vs remote set-url origin Cloning specific branch

Examples related to egit

How to resolve conflicts in EGit Push eclipse project to GitHub with EGit Egit rejected non-fast-forward 'cannot open git-upload-pack' error in Eclipse when cloning or pushing git repository Eclipse EGit Checkout conflict with files: - EGit doesn't want to continue git stash and git pull How do I set up Eclipse/EGit with GitHub? "Auth Failed" error with EGit and GitHub