How do I create a git repository over an eclipse project or vice versa?

I have a git repository that is just a directory tree (/myprogram/src/com/mycompany/test) with some source files. I wish to create an eclipse project around this repository. Both orders of create project in eclipse and git clone <url> <myprogram> from the command line give me a “folder already exists” error from whatever tool I use last. I could move the files manually to merge them, but it feels messy and I’m not 100% confident I know which files to touch.

How is this supposed to be done properly?

  • Is it a good practise to do version control from outside the IDE?
  • How do I ignore this Eclipse file in Git?
  • Importing gradle project, android error
  • egit does not show label decorations
  • 'cannot open git-upload-pack' error in Eclipse when cloning or pushing git repository
  • Git Working Directory to Eclipse Workspace
  • 2 Solutions collect form web for “How do I create a git repository over an eclipse project or vice versa?”

    You could do it by selecting Import -> Existing Projects into Workspace, select the directory containing your project (the parent of myprgram), and check the checkbox next to your project (myprogram).

    To have Git support in Eclipse, install eGit and then right-click your project, select Team -> Share Project -> Git, expand the triangle to select the existing repository and click Finish. This should give you Git annotations on your project.

    Another option might be to just select Import -> Git -> Git Repository (after eGit is installed) and import your repository (but I’ve never done that with a local repository). See also the eGit user guide.

    To resolve this I just ended up copying the git repository into a newly created project, but upon revisiting the issue I found a link here that suggests something slightly more elegant (but functionally similar).

    After creating a new project, use Import -> Filesystem and Select All. In my case, my repository already had a proper /src/com/… directory structure which merged nicely into the one set up by the new eclipse project.

    Git Baby is a git and github fan, let's start git clone.