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 Window → Show View → Other 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.
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.
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.
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 File → Switch Workspace → Other... 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 File → New → Other..., select Git → Git 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With