Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EGit / JGit » newbie import from git repository question
newbie import from git repository question [message #704624] Thu, 28 July 2011 21:56 Go to next message
Alberto Duina is currently offline Alberto DuinaFriend
Messages: 3
Registered: March 2010
Junior Member
Dear EGIT community,
Sorry if my question is probably obsolete.
I try to import a project from a git repository, my goal is to have the project into the git repository and a copy into the workspace, so I can add, commit etc into the local repository. But when I make the Team/Share operation I end with only the repository files and a workspace with no files.

Here are my step to step operations:

In Eclipse: >> IMPORT/GIT/Projects from Git/
Select a Git Repository: git://pacific.mpi-cbg.de/imagej.git
>> CLONE < H:/Documents and Settings/Alberto/git/imagej2 >

Now in the directory tree:
H:/Documents and Settings/Alberto/git/imagej2/ we have the complete project tree with files
H:/Documents and Settings/Alberto/workspace/ is empty

In ECLIPSE >> New Java Project NAME:imagej
>> IMPORT/GENERAL/File System/ browse to the git project

Now in directory tree:
H:/Documents and Settings/Alberto/git/imagej2/ we have the complete project tree with files
H:/Documents and Settings/Alberto/workspace/ we have the complete project tree with files

the two projects are still disconnected but when I try to connect them:
Eclipse >> Team/Share Project/Git/ Repository: < the git project >
if not select Use or create Repository in parent folder of project the working directory predefinited is the workspace and when pressed finish the projects are connected BUT the project into the workspace become empty (without files)
And if I use create Repository in parent folder of project i end with two git repositories (and if I am not in error the tutorial suggest not put the git repository into the workspace of eclipse).

Thanks in advance.
Alberto Duina
Re: newbie import from git repository question [message #705058 is a reply to message #704624] Fri, 29 July 2011 11:29 Go to previous messageGo to next message
R Shapiro is currently offline R ShapiroFriend
Messages: 386
Registered: June 2011
Senior Member
You did too many steps here. In particular you imported twice, and also created an entirely new project.

If the external Git repository is already configured as an Eclipse project (that is, it includes a .project file), and all you want to do is make a local clone you can work with, do the following:

1) Go to the "Git Repositories" perspective. Note the three toolbar items with "Git" in the name. Click the middle one, the one whose tooltip says "Clone a Git repository and add the clone to this view". By default the clone will be added in ~/git (or equivalent in Windows). You can put it wherever you want though. You can also change the default location in the egit preferences (Preferences -> Team -> Git, "Default Repository Folder").

2) Now you should have an entry in the Git Repositories list referencing your new clone. Click right on that entry and select "Import Projects..."

That's it, you're done.


If you already have a local clone, then in step (1) use the first Git toolbar item from the left instead, the one whose tooltip says "Add an existing local git repository to this view". Then proceed with (2) as above.


If the repository is not yet configured as an Eclipse project and you want to turn it into one, that's a different kind of question, not specific to egit. Basically you need to add a .project file of the right sort and commit it, along with other Eclipse metadata specific to the project type (Java projects need a .classpath, C++ projects need a .cproject, etc). Eclipse will help you configure the other files once it knows what kind of project you want it to be.
Re: newbie import from git repository question [message #706515 is a reply to message #705058] Sun, 31 July 2011 12:44 Go to previous messageGo to next message
Alberto Duina is currently offline Alberto DuinaFriend
Messages: 3
Registered: March 2010
Junior Member
Thanks a lot Shapiro,
unfortunately is not already an Eclipse project, so no .project file and I take the long detour. But remains the last curiosity: it is normal that when you select Team / Share etc, Eclipse move the entire directory project from the workspace to the git repository and nothing remains in the original workspace?
I ask this because if it is correct I have to change the backup path: instead of the workspace the git repository
Ciao,
Alberto
Re: newbie import from git repository question [message #706734 is a reply to message #706515] Sun, 31 July 2011 20:36 Go to previous messageGo to next message
R Shapiro is currently offline R ShapiroFriend
Messages: 386
Registered: June 2011
Senior Member
Creating an Eclipse from an existing directory is not hard, it's just off-topic. But here's a quick summary of how you can do that for a Git repository containing Java code. I'm assuming here your Eclipse includes the Java plugins. If your project is CDT/C++ or Python or whatever, adjust accordingly.

Run File -> Import -> Git -> Projects from Git. Then in the next panel pick 'Add', not 'Clone'. You already have a local clone, the one in "H:/Documents and Settings/Alberto/git/imagej2". The reason you got a second copy is that you cloned it.

Or you can use the Git Repositories view, as I described earlier to get at the existing clone.

At this point egit knows about your local clone. Since there's no .project file yet use the option "Import as General project". You can't "Import existing projects" because there aren't any yet, and you don't want the "New Projects wizard", since that will create an entirely new tree. Instead you want to convert the existing tree.

At this point you should have a generic eclipse project in your workspace. It will contain all the files of your local clone plus one new one called ".project".

Now right-click the project root and select Configure -> Convert to Faceted Form. This is how you can convert a General project into a Java (or C++ or Python or whatever) project. In this case the "Java" option should appear, since we're assuming your Eclipse includes Java support. Check that box if it isn't already checked, and proceed.

At this point you should have an Eclipse Java project. All that's left is to configure the build-path in the usual way: Build Path -> Configure Build Path. Here you can set the dependencies, specify the source directories, etc. For Java projects this step will add a file called '.classpath' and a directory called '.settings' with two files in it. For C++ projects it will add a .cproject and .settings.

Add the new files to Git, commit to your clone, and then push back to the origin so that your fellow developers don't have to go through all this.


As for "Share", you don't need to do it, as egit already knows everything it needs to. The purpose of "Share" is to tell Eclipse what repository you're working with. This can be handy for imported CVS or SVN projects but isn't generally necessary for Git or Mercurial.

Re: newbie import from git repository question [message #706765 is a reply to message #706734] Sun, 31 July 2011 21:28 Go to previous messageGo to next message
R Shapiro is currently offline R ShapiroFriend
Messages: 386
Registered: June 2011
Senior Member
<sigh>Too much context here distributed around. I hate forums for just this reason. Ignore my previous response, let me try again...</sigh>

Start like you did before:

Run File -> Import -> Git -> Projects from Git.
Click "Clone" and enter git://pacific.mpi-cbg.de/imagej.git as the repository. This will create a local clone of that repository.

When the clone is complete, select the newly added clone and click "Finish".

Or if you want to do all the steps manually, click "Next" and use the option "Import as General project". You can't "Import existing projects" because there aren't any yet, and you don't want the "New Projects wizard", since that will create an entirely new tree. Instead you want to convert the existing tree.

Either way, at this point you should have a generic eclipse project in your workspace. It will contain all the files of your local clone plus one new one called ".project".

DO NOT DO ANOTHER IMPORT. This is where you went wrong last time.

Now right-click the project root and select Configure -> Convert to Faceted Form. This is how you can convert a General project into a Java project (or C++ or Python or whatever). In this case the "Java" option should appear, since we're assuming your Eclipse includes Java support. Check that box if it isn't already checked, and proceed.

At this point you should have an Eclipse Java project. All that's left is to do any project-specific configuration. For a Java project you would want to configure the build-path. Other kinds of projects would have other sorts of configuration. The configuration step will probably add more files. For a Java project it will add .classpath and two files under .settings.

Add the new files to Git, commit to your clone, and then push back to the origin so that your fellow developers don't have to go through all this.


As for "Share", you don't need to do it, as egit already knows everything it needs to. The purpose of "Share" is to tell Eclipse what repository you're working with. This can be handy for imported CVS or SVN projects but isn't generally necessary for Git or Mercurial.
Re: newbie import from git repository question [message #895656 is a reply to message #706765] Sat, 14 July 2012 08:19 Go to previous message
Alistair MacDougall is currently offline Alistair MacDougallFriend
Messages: 1
Registered: July 2012
Junior Member
Thank you for the detailed answer given to this question. It was really helpful to have the steps gone through one by one, and helped me sort out the same issue.
Smile
Previous Topic:egit cloning issue
Next Topic:Code Style @version tag for revision history.
Goto Forum:
  


Current Time: Tue Mar 19 10:22:21 GMT 2024

Powered by FUDForum. Page generated in 0.03808 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top