Git Push Failed - 'push would result in a non fast forward-update' - github

In netbeans, while pushing the project at remote(Git), I am getting the error 'push would result in a non fast forward-update'

Don't forget to update first your Netbeans: bug 238398 shows that, starting NB8+, the error message is more explicit (revision 2a7a1c67f8ea):
Instead of
Push would result in a non fast-forward update.
Open output to see more information.
It now says:
Remote repository contains commits unmerged into the local branch.\n"
Do you want to pull the remote changes first?
That will help you trigger a git pull (as suggested here), needed before attempting a push again.

Related

STS getting this while pull/fetch latest changes Couldn't lock local tracking ref for update

Getting this issue in spring tool suit while fetching/pull latest changes from remote branch. i don't have git bash on my local previously it was working fine right now i am getting below mention issue.
Couldn't lock local tracking ref for update
I also encountered same problem
But I removed this problem using GITHUB Desktop tool.
Once I executed pull from STS, its showed the dialog box with error as shown above. and a up arrow got appended showing there are some commit to be pushed,
though I had not made any commits before this pull. The changes from pull were not added to my local project.
I checked on Github Desktop, and it also showed same arrow.
I pushed it from tool, and it was resolved. The changes from pull got added to local project.
While you don't have git bash, Eclipse is using its own JGit (java-based implementation of Git)
As recommended in "egit lock fail eclipse", do check if you have any "<refname>.lock" file under .git/refs/". (howlger refers to eclipse issue 417860:
I checked in jgit and egit sources and found that the only occurrence of the text "[lock fail]" is used when fetch fails to update a remote tracking branch.
This can happen if a previous crash didn't cleanup a "<refname>.lock" file which git creates as a lock to guard the ref against concurrent updates.
git remote prune origin
solved same problem for me

EGit: Issuing a fast-forward pull ~ How to configure fetch for a remote repository in EGit

So let me set up my scenario. I am using EGit 4.1.1 in Spring Tool Suite (Eclipse 4.5.1). My tech-savvy coworker and I have cloned the same git repository from a remote URL. My tech-savvy coworker, who prefers the command line, does his file modification using VIM, then issues the commands
git add .
git commit -m "Modified file"
git push
Now the change is in the remote repository. Now I, who am less CLI-prone and more prefer the GUI, am using EGit in Eclipse. To receive the change, I right click the project (which I originally cloned using EGit), go to Team -> Pull, and I am told that there is "Nothing to fetch". For sanity purposes, I have the "Git Reflog" view open, and I see that my coworker's change is not listed, and I begin to scratch my head.
So I go to the command line and I issue the command git pull, and voila!, it pulls in my coworkers change:
remote: Counting objects: 27, done.
remote: Compressing objects: 100% (10/10), done.
remote: Total 14 (delta 4), reused 0 (delta 0)
Unpacking objects: 100% (14/14), done.
From git://hostname.domain.com/git-repo
* branch master -> FETCH_HEAD
Updating 123ae12..68cd2f0
Fast-forward
Better yet, I go back to Eclipse, and I see the change in the "Git Reflog" view, listed as
Commit Commit Message Date Reflog Message
---------------------------------------------------------------
68cd2f0 Modified File 2015-12-23 pull: Fast-forward
So, I feel like what I am being told here leads me to believe that there is a Git concept that I am not familiar with - something that I'm probably just missing. So...
Is there anything obvious I am missing here about the workings of git?
I am assuming that fast-forward means I am just moving my HEAD forward in the same branch
How do I accomplish this command-line "git pull" in Eclipse?
Edit: To address VonC's answer, I have added this information that is both more information and a solution to this question.
From the command line, when I run (from the repository) cat ./.git/.gitconfig, I get the following output:
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
ignorecase = true
[remote "origin"]
url = git://hostname.domain.com/git-repo.git
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
remote = origin
merge = refs/heads/master
However, when I go into Eclipse and look at the fetch configuration, it is blank.
To add to VonC's answer, what this means is that I missed a step when I originally configured the remotes for the git repo when I used EGit to configure it. Since I didn't have fetch configured for the repo, Eclipse was giving me the error "Nothing to fetch" - where perhaps it should have given me a more meaningful error like "Fetch not configured for this repository. To configure, you must..." Maybe I'll fix that later since EGit is open source.
To fix this in Eclipse (EGit), do the following:
Ensure the Git Repositories view is open.
Select the specific git repo, and expand it till the specific remote in remotes is expanded:
Right click the incoming origin and choose Configure Fetch
In the dialog, if you see no fetch configured at all, select Add next to the Ref Mappings pane
In the dialog, for Source, type refs/heads/* (despite the "Not found in remote repository" message. Select Next.
For Destination, make sure refs/remotes/origin/* is filled in (it may auto-populate). Make sure Update the local repository even if data could be lost is checked. Click Finish.
Now in your Configure Fetch dialog, you will see the new ref mapping: +refs/heads/*:refs/remotes/origin/*. This matches what is in the .gitconfig file.
Now click Save if you plan to fetch later, or Save and Fetch if you would like you update your local repository.
I'm not totally sure why EGit didn't do this automatically, perhaps that's a question for another day.
First, the reflog would not show you anything before a fetch (in command line or Eclipse): it records changes from the local clone only.
Second, check your .gitconfig to see how the remote origin is configured (also seen here).
You need to have a line for fetching:
fetch = +refs/heads/*:refs/remotes/origin/*
By default, the command line git fetch would use the current branch:
refs/heads/<head>:refs/heads/<branch>

Failed merge in EGit

I did a fetch from my remote origin to get the latest master branch that my friend had pushed to. I wanted to merge with my own master after the fetch, but whenever I do a merge with origin/master it just says "Failed". I've made hard resets before trying again with same result.
Since "Failed" is pretty vague I'm asking here what to do.
I have looked on the Egit wiki, but they don't mention failure as a possible result. This tutorial says that "A Failed result may occur when there are already conflicting changes in the working directory.", that's all I've found by googling.
Egit 2.2.0
Eclipse Build id: 20130225-0426
So the problem was Egit failed a merge without saying why.
After playing around in the staging view and, by a leap of faith from someone not entirely comfortable with Git, added all the unstaged files to the index (which is strange since I did a hard reset, why should there be differences?) I committed it. After I had done the commit, another file (a .jar) popped up in the unstaged list (why wasn't it there until I made my commit? Seriously). I added it to the index and committed. Finally there were no unstaged files.
I tried merging, and it worked. At last I got the "conflicted" result instead of "failed". Added everything to index and committed. Finally I seemed to have merged successfully, and I could push.
Honestly can't tell if I made mistakes or if Egit doesn't work properly.
In the Git repositories view.
1. right click the local -> master branch
2. select push branch -> next
3. it pop up a 'select push destination' window, check the 'force update' in it.

How to fix the pushing rejected and asked to pull when pulling results in "everything is up to date"?

Using EGit with Eclipse when I try to push my code into the remote repository I get an error message saying that I should pull first, as shown in Figure 1.
When I then try to pull from the remote repository I get a message saying that everything is up to date, as shown in Figure 2.
How do I fix this problem?
Make sure that:
you are using the latest version of EGit (2.3+)
you have stashed/commit everything before pulling (as in this thread)
you are not in a detached head mode (as in "can't push upstream using EGit")
The OP Krige adds:
in the end I noticed a class file was mentioned in the DIRTY_WORKTREE error message.
I deleted that file from the file system, did a pull, resolved the conflicts and pushed.
Everything seems to work fine now.
If you have the DIRTY_WORKTREE issue and you are not able to delete the file (for whatever reasons), you should do a pull, or replace with HEAD and then add to Index. This will resolve the conflicts (assuming use of the merge tool) and you should then be able to commit/push your changes, or else pull again.

NetBeans non fast-forward update

I am using NetBeans 7.2.1 and am having trouble pushing a file after it has been committed.
The file is called 'test.php' and is a new file that has not been pushed to the server yet. The file has no PHP errors and the commit works successfully.
However, when I try and 'push' the file, the following error message pops up:
Push would result in a non fast-forward update.
If I do a 'pull', the pull completes successfully. If, after I have done the successful pull, I try and do a 'push', the same 'non fast-forward update' error pops up.
I'm facing the same problem.
Please try pull and then merge.
Do a pull then merge the branches so it can track updates. Had the same problem you had on 7.4 and this fixed it.