3

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.

1

6 Answers 6

6

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.

Sign up to request clarification or add additional context in comments.

Comments

3

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)

6 Comments

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.
Is this still what you would recommend?
@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.
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: 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.
|
1

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.

Comments

1

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 Comment

Today I recommend reading the GitLab Flow documentation.
0

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.

Comments

0

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).

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.