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.
-
I`ve got the same problem after creating a new repo with "Initialize this repository with a README". I removed that one and create ones again without this chechbox. – andrew Jan 23 '16 at 16:54
-
@andrew is right – Dany Wehbe Mar 28 '19 at 09:08
10 Answers
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.
Configure the 'fetch' to fetch the branch you originally pulled from.
Fetch the remote branch.
Merge that remote branch onto your local branch.
Commit the (merge) change in your local repo.
Push the change to the remote repo.
In detail...
In eclipse, open the view 'Git Repositories'.
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.
Look for the green arrow pointing to the left, this is the 'fetch' arrow. Right click and select 'Configure Fetch'.
You should see the URI, ensure that it points to the remote repository.
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'.
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'.
Click 'Save and Fetch'. This will fetch that remote reference.
Look in the 'Branches' folder of your local repository. You should now see that remote branch in the remote folder. Again, I see 'master'.
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'.
Process through the merge.
Commit any changes to your local repository.
Push your changes to the remote repository.
Go have a tasty beverage, congratulating yourself. Take the rest of the day off.

- 3
- 1

- 2,639
- 1
- 12
- 8
-
7This should be marked as the answer. Worked like a charm. This problem occurs even though I didn't add any files (the usual README-file) upon creation of the repo on GitHub for my project in Eclipse. Thanks a lot for the easy to follow step-by-step explenation. – rbaleksandar Mar 03 '14 at 20:21
-
This problem took me a year to sort out, until I read your post. In my case, I had no remote but Eclipse created a default one called 'origin'. – Eugene van der Merwe Apr 15 '14 at 18:48
-
Sweet, finally i can merge with Eclipse. The key point here is to use the Git Repositories view to do the merge, and not the usual Team Synchronise view. It would be good if in the team synchronise view eGit could have disabled all the options that do nothing. – dan carter Jan 13 '15 at 03:07
-
1While this does work, it creates an unnecessary merge commit. You should use rebase here, which is fine because your changes are only local so you're not changing any published history (and if you did that, git would yell at you for a non-fast-forward push anyway). I like MYN's answer. – alexia Mar 27 '15 at 19:17
-
1Right click on the project and then `Merge` in master and then right click again on project `push branch Master` worked – user1207289 Mar 31 '17 at 16:32
-
-
oooo.... this "solution" blows up my project... it adds some strange line with ">>>>>>" signs and "HEAD" text... And now I have a lot of errors... OMG, i hope I will be able to disassemble a jar file which I made before do this s... – Vali Maties Aug 16 '20 at 19:37
-
-
This helps me only once, but in any another change, if it's clear that nothing was changed on the remote, it's throwing again rejected-non-fast-forwad – lingar Oct 27 '21 at 13:33
In my case I chose the Force Update
checkbox while pushing. It worked like a charm.

- 2,889
- 25
- 40
-
This worked for me too. I had the condition of the OP after "amending" a commit. And fetch gave me "nothing to fetch" – Twilite Nov 09 '18 at 10:16
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.

- 1,955
- 19
- 33
-
4in this case git is quite stupid, I pushed all the changes to the remote. and I am the only one work on the project. Why on earth I need to pull the remote before I can push again???? the pulled change would come from my local originally – Junchen Liu Jul 06 '16 at 11:04
Applicable for Eclipse Luna + Eclipse Git 3.6.1
I,
- cloned git repository
- made some changes in source code
- staged changes from Git Staging View
- 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
- from Git Repository perspective, right click on the concerned Git
project - 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'? - select
Rebase...
- this open a popup, click onPreserve merges during rebase
see why
What exactly does git's "rebase --preserve-merges" do (and why?) - click on
Rebase button
- if there is/are a
conflict(s)
, go to step 6 else step 11 - a
Rebase Result
popup would appear, just click onOK
file comparator
would open up, you need to modifyleft side file
.- once you are done with merging changes correctly, goto
Git Staging
view stage the changes
. i.e.add to index
- on the same view, click on
Rebase
->Continue
. repeat 7 to 10 until all conflicts are resolved. - from
History
view, select your commit row and selectPush Commit
- select
Rebase Commits of local.......
checkbox and click next. refer why - Git: rebase onto development branch from upstream - click on
Finish
Note: if you have multiple local repository commits, you need to squash them in one commit to avoid multiple merges.

- 1
- 1

- 1,843
- 1
- 22
- 25
-
I agree with using rebase instead of merge. It's better as it doesn't create an unnecessary merge commit. (Off topic: Stack Overflow is being entirely ridiculous and rejects my comment solely based on the fact that I originally wrote "+1 for". My comment is perfectly constructive, thank you.) – alexia Mar 27 '15 at 19:21
Configure After pushing the code when you get a rejected message, click on configure and click Add spec as shown in this picture
Drop down and click on the ref/heads/yourbranchname and click on Add Spec again

- 551
- 5
- 15
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

- 31
- 1
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.

- 524
- 4
- 16
In my case i forgot to pull the new changes from git
- Right click on the project Fetch From Upstream
- Right click on the project Pull
- Right click on the project Push to Upstream

- 101
- 1
- 2
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.

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

- 515
- 5
- 7