6

I have Eclipse Juno with EGit and a project that I've been working on for a while. I've decided to move it to Git, so I created a Github account and downloaded and installed the program. The repository is at C:\Users\username\GitHub\project_name\, but all it has is the README.md file.

How can I configure Eclipse to use my existing source code (in a workspace separate from the git folder) to work well with git? I've tried using WindowShow ViewOther and selecting "Git Repositories," but other than adding a repository (which I have done) I can't figure out how to sync the code.

I've read this question but I get the impression that those answers will perform a one-time commit, instead of a sync.


To clarify: The repository does not have any code. I would like my existing code (in the Eclipse workspace) to be synced to the new repository.

5
  • 1
    Git != github. Just point Eclipse at the existing git repo. The empty repo with the readme is useless to you.
    – Matt Ball
    May 24, 2013 at 4:37
  • That's my question - how do I point it there and have it sync my code?
    – wchargin
    May 24, 2013 at 4:38
  • Sounds like "in a workspace separate from the git folder" is the problem. Why isn't the folder containing the code part of the workspace?
    – Matt Ball
    May 24, 2013 at 4:47
  • @MattBall: The workspace contains the code. The git repository is separate from the two. How can I make the repository basically point to the workspace?
    – wchargin
    May 24, 2013 at 4:49
  • You don't. You turn the workspace (or one of its subdirectories) into a repository with git init.
    – Matt Ball
    May 24, 2013 at 5:07

1 Answer 1

6

If you already have a git repository in place, first copy all your files to that directory (yes, manually) and do a git commit -a to commit all the files into the repository. I'm assuming here that you've already initialized the repository at C:\Users\username\GitHub\project_name\ with git init.

In eclipse, go to FileSwitch WorkspaceOther... and point it to a workspace of your choice that can be completely different than the location of your code, or your earlier workspace. In fact, don't point it to the directory which contains your git repository.

Once you have a clean workspace, go to FileNewOther..., select GitGit Repository and enter the path of your git repository (C:\Users\username\GitHub\project_name\). Enter a name for the repository, and click Finish.

I would really recommend you read at least the first few chapters of the git book to understand how git works, and to help you push and pull code to and from remote repositories.

If your existing repository is not git, you're going to have a hard time keeping the directories in sync. You might want to setup rsync to sync the directories. There is no way AFAIK for eclipse to automagically keep the two repositories in sync.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.