Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to download/clone a new branch from my server git repository into an already created local git repository in my PC with Eclipse EGit

Tags:

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.

like image 408
jdias Avatar asked Sep 07 '11 06:09

jdias


People also ask

How do I clone a new branch in Eclipse?

In order to checkout a remote project, you will have to clone its repository first. Open the Eclipse Import wizard (e.g. File => Import), select Git => Projects from Git and click Next. Select “URI” and click next. Now you will have to enter the repository's location and connection data.

How do I clone a git repository in Eclipse?

Open Eclipse and choose Import –> Projects from Git (with smart import) Choose the Clone URI option in the Git import wizard and click Next. Confirm the URI, Host and Repository path parameters and click Next. Choose the Git branches to clone from the remote repository and click Next.

How do I create a new branch in an existing repository?

The git branch command can be used to create a new branch. When you want to start a new feature, you create a new branch off main using git branch new_branch . Once created you can then use git checkout new_branch to switch to that branch.

How do I clone a specific branch from a git repository?

In order to clone a specific branch, you have to execute “git branch” with the “-b” and specify the branch you want to clone. $ git clone -b dev https://github.com/username/project.git Cloning into 'project'... remote: Enumerating objects: 813, done.


Video Answer


1 Answers

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 :)
like image 140
mozzbozz Avatar answered Sep 29 '22 14:09

mozzbozz