Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I configure Eclipse to use an existing git repository with existing source code?

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.

like image 751
wchargin Avatar asked May 24 '13 04:05

wchargin


People also ask

How do I add an existing Git repository to Eclipse?

Copy the GitHub URL of the repository to the clipboard. 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.

How do I import existing Git repository?

Select Repos, Files. From the repo drop-down, select Import repository. If the source repo is publicly available, just enter the clone URL of the source repository and a name for your new Git repository.


1 Answers

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.

like image 99
Anand Avatar answered Oct 24 '22 22:10

Anand