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.
Applicable for Eclipse Luna + Eclipse Git 3.6.1
I,
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
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'?Rebase...
- this open a popup, click on Preserve merges during rebase
see whyRebase button
conflict(s)
, go to step 6 else step 11Rebase Result
popup would appear, just click on OK
file comparator
would open up, you need to modify left side file
. Git Staging
viewstage the changes
. i.e. add to index
Rebase
-> Continue
. repeat 7 to 10 until all conflicts are resolved.History
view, select your commit row and select Push Commit
Rebase Commits of local.......
checkbox and click next. refer why - Git: rebase onto development branch from upstreamFinish
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
Drop down and click on the ref/heads/yourbranchname and click on Add Spec again
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.
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.
Source: Stackoverflow.com