EGIT rejected non-fast forward - eclipse

I'm on Eclipse 4.2.1 (Java) and trying to use EGIT. My account is all set up on Github. No one else is working on it so there are no changes. I have a very simply project containing a single file with one print statement.
I created my local repo and added the project. (project explorer shows: [gitrepo1 master])
In project explorer:
right click on project -> team -> remote -> push
But I get: master: HEAD [rejected - non-fast-forward]
I've configured the push:
Branch -> master
URI -> ssh.git#github....
Ref mappings -> HEAD:/refs/heads/master
What am I doing wrong?

We had this problem, because we amended a commit after pushing it.
The solution was to merge origin/master (in Branches > Remote tracking), then push.

egit works by using jgit which is an implementation of git that is using java. the best thing to do is verify that the repo works with the normal git client. From your question it is not possible to know exactly how things ore configured.
When you get the error message that you could not do a push because it is not a fast forward, it means you need to do a pull first then, do the push, so try that.

Same cause as Bernát: I amended a commit after pushing it. Merge failed because of conflicts.
My way out: Context menu 'Team/Reset' selection 'Remote Tracking'/'origin master' option 'Mixed'. After that all my changes since last push were marked and I could commit and push.

Related

Push to main instead of master from eclipse to git

I have been searching and I found git commands to change the repository but I'm new on github and I don't know how to make that from eclipse, everytime I push I make the changes on the master branch instead of the default main, when I try to push the main it says non fast forward and I can't do it, thanks.
Select Team > Advanced > Rename Branch
Rename local as main
Rename remote to main
when you first commit your project in eclipse and then you click on push
after filling the information of the repository you get this
you will write main here insted of master and your project will be pushed directly to the default main
my solution is only when you first upload your project to GitHub

How do I get a new branch to show up in Eclipse Git Remote Tracking?

I have an existing Eclipse git project, with a master and development branch present in both local, and remote tracking. I have just added a new branch in my git repository, but I can't figure out how to get it to show up in Eclipse.
I have tried to read up on the subject, but it seems like it is just expected to automatically show up. I have found a lot of similar questions, but they all seem to deal with the issues of a completely empty remote tracking folder, instead of my problem of only a single new branch missing. I already have Master and Develop present.
Here is what does not work:
Clicking refresh in the Git repositories window.
Any kind of synchronize, pull or other update I can find
Here is what would work:
Right clicking the remote tracking folder, and selecting "Paste repository path or URI". If I do that, and select the exact same path as is already there, I can see my new branch. This action does require that I completely clone the whole repository to an empty folder again, and that can't be how this is intended to work.
I believe it might work to use some kind of command line tool, but I really want an Eclipse solution to this, as I feel sure it exists, and I am just missing something.
In the Git Repositories view:
Right-click the repository and choose Fetch from Upstream
If the new branch will not shown up below Branches/Remote Tracking, you have to configure fetch:
Right-click the fetch node below Remotes/origin and choose Configure Fetch...
In the Configure Fetch make sure there is only the single Ref mapping (assuming the remote is named origin) +refs/heads/*:refs/remotes/origin/*:
In case you do not see Fetch from Upstream after right-click the repository, you may look for Fetch from origin.
For me the solution was almost what Joshua suggested, however it did not work as described. For me the solution was to configure the [remote "origin"] property as follows:
[remote "origin"]
url = your_git_url.git
fetch = refs/heads/*:refs/remotes/origin/*
Alternatively, you can do it from the Eclipse UI too:
Fetch from origin... then hit Configure... and in the configuration window hit Advanced... and there you have the option to Add predefined specification where you can selec Add All Branches Spec. This will result in the same configuration as above:
Maybe you have to remove your original entry which will be pointed out as a duplicate by Eclipse.
You need to modify the "config" file in your local git repository folder. For example, you cloned a remote branch Project into c:\git\MyProject local folder. In this folder there is a hidden folder ".git" that has a "config" file. There is a section in this file resembling the below
[remote "origin"]
url http://xxxxxxxxxxxxxxxx
fetch = +refs/heads/Project:refs/remotes/origin/Project
You need to modify this section as below
[remote "origin"]
url http://xxxxxxxxxxxxxxxx
fetch = +refs/heads/:refs/remotes/origin/
Then go back to Eclipse IDE, right click on the repository and do a "fetch from origin". Now all the branches will show up.
What I did:
1: disconnected.
2. refresh and pull. Then, it shows the new branch
3. create local and pull.

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>

Eclipse Git (egit) pull and push to upstream option not available some times.?

Right click on Project -> Team -> push and pull not available(EGIT)
Eclipse pull and push to upstream option not available some times.?
i am able to see commit every time but push ,pull,remote are missing some times
How to make appear them always
Basically your eclipse is disconnected with git.
Right click on project -> Team -> share Project -> Select Repository type as git -> Next -> chose your project and finish.
For me this disappeared as well, while the .git/config is unchanged and good.
Refresh did not help.
But Eclipse restart did the trick.
The options disappear sometime if the EGIT is not able to find the path from which it should Fetch, Pull and Push.
Check if the origin is deleted.
Goto the GIT Repositories View
See for the Remotes -> origin
If the Push and Pull in origin are deleted. You will have to add the URI by right click on the origin, add origin and configuring the Push and Fetch URI.
I hope this will be helpful.
Yes, this is a frequent annoyance. If Refresh doesn't work, I use "Close Project" followed by opening it again.

Eclipse/Egit, Push to Remote menu choice is grayed out

I created a repository on GitHub. I set up a local git repository using Eclipse and Egit.
With Team > Remote > Push. I managed to push the local repo to the one on GitHub.
Now I expected to be able to use the Team > Push to Upstream (as well as fetch from upstream) as a one-click push (and pull/fetch), but this menu choice is not available (grayed out). I have to use Team > Remote > Push to each time manually fill in the info (ctrl+space helps).
Following this, I created a remote configuration and pushed from the repositories view, and I can see the remote GitHub repository listed under Remotes but still the Team > Push to Upstream command is grayed out in the menu.
Could someone please give me a hint as to what I have may done wrong?
Here's what I did and this worked fine:
Right click your project, choose Team→Show in Repositories View. You will switch perspectives and be in the Git Repositories tab.
Right-click "Remotes" and choose "Create Remote". For "Remote name", enter "origin". Click OK.
Click Change. Enter your information as you did during your initial push. Click Save.
You should now be able to push by merely right-clicking on your project, then Team→Push to Upstream.
Because the remote was added under the project in question, each project can have its own upstream origin and they will not interfere (whereas the Window > Preferences solution is a global setting).
Based on your description of what you did, it appears you attempted this - but possibly did not use the name "origin" for the remote, which is absolutely necessary. I stumbled across this solution by pure chance.
I had this problem and thankfully found a way to re-enable the "Push to Upstream" option.
Go to Window > Preferences > Team > Git > Configuration.
Select the Repository Settings tab and then the repository that represents your project.
Click "New Entry..."
The key is remote.origin.url
The value is the url you copy from github. It's usually offered predominantly on whichever site you register with.
Perhaps there is a neater way of achieving the same thing. Once I reached this far I stopped looking because it works now.
You need to have the following type of configuration in that repository's .git/config file:
[branch "master"]
remote = origin
The remote setting can be any of your remotes or just a value of .
You can edit the repository's config by selecting the Properties menu item from the context menu for the repository in the Git Repositories view.
I came here searching for solution to solve similar problem with bitbucket - although none of the two highest votes answer didn't work for me, it proved that I had option "Put branch...", when I tried to do this, it says "Non fast-forward", but when I successfully made "pull", I was able to push to upstream.
Maybe it will help someone :)
This post might be a little old, but I had the same issue with one of my repos the following information from this link worked for me: Adding a remote to an existing git repo
The part i want to highlight from that article is the following:
[branch "master"]
remote = origin
merge = refs/heads/master
When I made the change in the .git/config and refreshed eclipse the "push to upstream" link worked for me. Keep in mind, I am assuming that you have a remote configured in your Git perspective for your remote repository.
In my case all git commit/push operations are inactive. I fixed the issue by placing the repository folder under git directory.