I use Eclipse to edit Java, and use Git for my VCS. Should I have my local repository in my workspace, or outside it, and copy the files every time I want to commit? I know I can do it every way, but I'm new to Git, and wondering which way is better.
6 Answers
The best practice at the moment is to create your git repositories outside of your workspace. The most common form of repository contains a couple of projects in some logical structure, and the workspace likes projects in a flat structure. See the EGit User Guide/Considerations when creating Repos for more details.
When importing the projects into the workspace via standard import or EGit, Eclipse is happy to point to the other location on disk.

- 10,614
- 1
- 25
- 32
I just have the local repository in the workspace. I'm not sure why you'd want to keep the two separate - why create extra work for yourself?
Code, commit; code, commit... (where "code" includes tests of course)

- 1,421,763
- 867
- 9,128
- 9,194
-
I figured. I'm new to Git, so I thought maybe there were some standard practices for this. But I was just wondering, thanks for the answer, that'll do. – Anonymous Oct 26 '11 at 17:02
-
-
@Mark: Yes, absolutely - in terms of not copying the code around. I'm fine with the workspace metadata being separate, but I wouldn't want to have two copies and an error-prone sync system in place. – Jon Skeet Dec 15 '16 at 17:20
-
Then maybe you can help me with the paths. If you have linked/dependent projects in `/workspace/project1` and `/workspace/project2`, how would you set up the repo? – Mark Dec 15 '16 at 17:39
-
@Mark: I suggest you ask in a new question, after showing what you've tried. Asking additional questions in comments in a 5-year-old question isn't ideal. – Jon Skeet Dec 15 '16 at 17:40
-
OK: http://stackoverflow.com/questions/41171813/workspace-and-repo-paths-arrangement-for-eclipse-and-git – Mark Dec 15 '16 at 19:22
Inside it. Creating an external one that you have to remember to copy files to, etc. starts to defeat some of the reasons to use a VCS like GIT :)
You can also always create and 'checkout' branches if you want to get some code separate for now. Then both the branch code and the base code are both in VCS and you'll always be able to mange them for merges, etc.

- 93,410
- 97
- 333
- 497
If you are used to subversion you may have this thoughts first. But working with Git means to have the complete repository as your own workspace.
You should configure Eclipse to use git and add to your .gitignore file the project folder if you do not want to have it in the repository.
As development workflow I can recommend the method Vincent Driessen bloged about: http://nvie.com/posts/a-successful-git-branching-model/

- 1,390
- 11
- 15
-
Today I recommend reading the [GitLab Flow](https://docs.gitlab.com/ee/workflow/gitlab_flow.html) documentation. – hellectronic Oct 22 '18 at 12:53
You have to remember that Git is just a single .git directory in your project. So you could just have one project folder that you work off of in your Eclipse workspace. If you are using Eclipse I recommend the EGit plugin.

- 3,115
- 3
- 26
- 39
Inside it; especially if all of your work is in Eclipse. Managing the repo outside of Eclispe is going to make it much more likely to add files you don't want in your repo (ex war/WEB-INF/classes). Also, managing from Eclipse means it will naturally be easier for other developers to sync your repo and setup their environment in Eclipse.
I suppose a good exception to this rule would be if you were maintaining a dev-environment folder of some sort (ex, jdk used/eclipse install used/jars for 3rd party libraries to add to build path/etc). So I guess the best general rule to follow would be if you're using Eclipse to change the files, you should also be using Eclipse to manage the file in your git repo.
Also, use EGit if you aren't already (I think others have mentioned this).

- 6,141
- 2
- 38
- 65