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

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>

Related

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.

How to view file changes before pulling through GitHub on RStudio?

I'm transitioning from using Subversion in Eclipse for code management to GitHub in RStudio. It's starting to make sense, but I can't seem to figure out how to pull effectively.
Specifically, if I use the Pull arrow in RStudio, every file change in the repository automatically updates my local files without warning. I can see how many files were updated, but not what changed!
Here are the questions I'm hoping to get help with:
1) Can I preview the repository file changes in RStudio before I pull them locally? With SVN in Eclipse, there was an indicator showing files with a difference, and the option to view side by side.
2) If multiple files have been changed on the repository, is it possible to pull just 1 locally?
3) How can I revert a local file to a previous version?
Right now I've been trying to do this all within RStudio for simplicity. I haven't used things like the GitHub desktop client.
I appreciate the help!
I would suggest you better get used to the git's own tools to stay informed about your repository.
For example you could do following.
Before you pull, check your current commit logs
git log
This should show you how your current commits stack up. Note the latest commit id (first 4-5 letters would usually do)
Now after pulling you can see the difference using following command
git diff --color your_previous_commit_id..HEAD
If you don't like the changes and want to go back,
you can just reset to your favorite commit with following command. BTW run "git stash save" to keep a copy of your uncommitted changes.
git reset --hard you_favorite_commit_id
Note: that this will delete all your uncommitted changes unless you stashed them and put your local branch behind the remote repo branch you are tracking again.
Wondering where to put these commands? Check https://git-scm.com/downloads.
What's good about using these git tools is that if you switch between IDEs you don't need to search for same functionalities you had in your earlier IDEs.

EGit push to remote is opposite what I expect it to do

This is what I want to do:
use Eclipse and Git (EGit)
use EGit to clone a remote repository to my local copy
make changes to my local copy
push those changes back to the remote repository
This is what I see:
after the push, the staged changes on the remote repository are the opposite to the changes I made.
Let me give an example and maybe someone can tell me where I have gone wrong.
I create a directory called C:\GIT\remote which contains a file called readme.txt which contains the string Hello World!
I turn this into a Git repository, I stage the readme.txt file, it shows:
new file mode 100644
## -0,0 +1 ##
+Hello World!
I commit this change at the remote repository. The remote repository contains no unstaged changes
Start Eclipse, import->Projects from Git->Clone URI. Location URI = C:\GIT\remote, Next, Next, Destination Directory: C:\GIT\local, Next, Import as General Project, Next, Finish
This creates a git repository in C:\GIT\local, with the readme.txt file and a .project file. As expected.
In Eclipse, I open the readme.txt file and edit it to say Goodbye World!. Save.
Right click on project in Project Explorer and: Team->Commit
Files to change are: readme.txt and .project. I enter a commit message "made changes" and click Commit.
Eclipse now shows that the local repository is 1 commit ahead of the remote repository. (Am I right?)
Right click on project in Project Explorer and: Team->Push to Upstream and it shows my comment and the remote repository details:
Now, when I look at the Staged files on my remote repository, I see this:
It's showing that the .project file needs to be removed (instead of being added), and that the change to the readme.txt file should be the reverse of the change I just made:
## -1 +1 ##
-Goodbye World!
+Hello World!
The C:\GIT\remote\readme.txt file contains the string "Hello World!". The staged patch doesn't even make sense according to the contents of the file.
I am puzzled.
No, those are the staged changes on remote. Not the commit history (the git log). Those are two different things.
The "Git GUI" is showing you the changes that you would need to commit directly to the remote repository to bring it into sync with the remote repository's working directory, which is still in the old state - out of date.
To avoid this confusion, developers often make the remote repository a bare repository - one with no working directory. Then it can only be pushed to and pulled from - not committed to directly.

Eclipse-fetch says my Git repo is current so what's the ↓13 mean?

As a git noob, Eclipse is not helping my confusion... I switched to me local master branch and ran a fetch with the settings below:
Firstly I don't understand why the "Next" button is disabled. Secondly when I run the fetch using "Finish", it tells me I am already up to date (makes sense as I already fetched). So what does the ↓13 mean? Isn't it telling me my local branch is behind the remote branch? Or that the remote branch is itself behind... but this is the remote master so what can it be behind of?
It means that you are 13 commits behind the origin.
If the arrow is pointing up, that means that your branch is X commits ahead of the origin.
As far as your Next button being grayed out. I believe it's because you havn't selected the Ref yet. Click the ref, and then you should see it.
FYI - when i started out with Git, i tried to use the eGit plugin for Eclipse, and I can say to you as a new person in Git. Use command line! I've had my local git repositories corrupted from the plugins, and it's not very intuitive.

EGIT rejected non-fast forward

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.