22

This is driving me crazy.

I created a git repository in a Linux server hosted by my hosting company.

I cloned it to a local copy using Eclipse EGit.

I then created a branch in the original git repository in the server.

How do I copy the branch to my local copy using Eclipse EGit?

When I open Git Repositories inside EGit I see:

- Local
-- master

- Remote Tracking
-- origin/development
-- origin/master

How can I get the origin/development in my local using EGit?

I know I could create a new clone, but I don't want to do that as I believe there must be a way to get only the new branch.

Second question - where is the pull command inside EGit? I was able to find the fetch command, but when I run it it says that there is nothing to fetch. The RefSpec is:

+refs/heads/*:refs/remotes/origin/*

Third question - is there a way to process git commands from a command line inside Eclipse in my Windows system? I thought about trying to do a pull from a command line, but I can't find it in my local system.

Thank you.

jdias
  • 5,572
  • 4
  • 22
  • 25

4 Answers4

23

I've also been searching around some hours to find out how to get a remote branch in Eclipse EGit...

The solution is stated in this Bugreport. And it is really easy if you know how to do it - no need for using the command line version of git, which - even though it works in 99% of all cases - can be risky as I already had problems that it interfered with Eclipse and EGit.

Just follow these steps:

  1. First make sure you have opened the EGit Repository view. If you haven't opened it already, go to "Window → Show View → Other..." and from there select "Git → Git Repositories".
  2. In the Repository view choose "Branches → Remote Tracking". You should see your remote branches there already (example: origin/new_feature).
  3. Right click on the remote branch you wish to have with your local branches. Choose "Create Branch..."
  4. The default values should be OK. Normally you should not change anything here. Please note that you should not change the "Pull strategy" to something else than "Merge" if you don't know what you are doing. Otherwise pulling upstream changes might result in a loss of data.
  5. Click on OK "Finish" and you are done :)
mozzbozz
  • 3,052
  • 5
  • 31
  • 44
  • It's pretty bad that the plugin doesn't pick up and set the expected (for example "new_feature" but instead sets a random [in effect] alphanumeric name) making you think that this option is not what you want. :-( – Tasos Zervos Dec 21 '17 at 15:20
19

Your fetch is up to date because you already have everything copied to your local repository. A pull will merge origin/development into master, which isn't what you want. You want to create a new branch with origin/development as the starting point. I don't know how to do it with egit, but on the command line, you do:

git checkout -b development origin/development
Karl Bielefeldt
  • 47,314
  • 10
  • 60
  • 94
  • thank you for the answer. I finally found out that I can't submit git command line instructions from EGit (at least I believe I can't). I downloaded Git for Windows and I should be able to execute the command you suggested. I will report back success or failure. – jdias Sep 07 '11 at 07:12
  • 1
    It does work. I have decided to stop using Egit menus to issue git commands. I am now using the command line exclusively. This way I don't have to guess how Egit is going to execute an action when I press a menu button. I simply type what I want in the command line and I know how it is going to respond. I am marking this question as answered. Thank you Karl. – jdias Sep 16 '11 at 17:55
4

I have been facing the same problem, and here is how I solved it:

  1. Open Git Perspective

  2. First you must have the branch that you want to check out, in your repository under Remote Tracking. My problem was that I couldn't see the remote branch here, so in order to solve this - execute a Pull on the repository, and this command should get you all the branches under Remote Tracking

  3. right click the (remote) Branch, Check Out, Check out as new local branch
razvang
  • 1,055
  • 11
  • 15
2

To get other branches in sts , if pull didn't work then try this Team >> Remote>> Cofigure fetch from upstream stream>Advanced> Check branch you want in source ref: > then add spec

RoshanS
  • 89
  • 2
  • 5