Reputation: 363
The only way I seem to be able to get use git in eclipse is to create a non-git project then turn that into a repository. This ends up moving the project out of the eclipse workspace on the file system. I then have to delete the project(it's still in the git repository), then import a git repository after creating a branch and clone it to get it back into the eclipse workspace.
Is there a simpler way?
I simply want to create project that is really a clone from a local repository. Essentially I have two copies on my HD but I can commit the eclipse project to the git repository. Unfortunately there has to be a better way?
Upvotes: 1
Views: 3691
Reputation: 36
To answer this question involves three steps.
Switch to the Git perspective. Click on Create a new Git Repository.
When a dialog appears select a directory where you would like your remote
repository to be. This is were your project will be push
ed to. You will also
want to select the Create as a bare repository option.
That's it for this step. You should now have this repository in your EGit repositories list.
There are two ways to share a project so that it remains in your workspace. 1. Make the project directory a repository 2. Make the whole workspace directory a repository
The first option option is not recommended by the Eclipse team. This issue is described in more detail at Why is not recommended to have an Eclipse project folder as a Git repository?.
The basics of the issue are twofold:
Issue 1 isn't solved here. Issue 2 can be solved by connecting to a remote repository as show later.
To share the project as a repository:
Next you'll want to connect your newly created repository to the remote repository. That's covered below.
The second options allows multiple projects to be added to your repository. In fact any new project you create will automatically added to the repository.
Automatically adding projects can cause some issues.
One issue is that, if there are changes in multiple projects, staging those changes can take a bit of wading through. Using a Tree presentation when staging can simplify things.
Another more serious issue occurs when importing a git clone of a project into the workspace. This importing will create nested repositories. Nested repositories can cause problems according to this post. By default Eclipse doesn't import the git clone of the project into the workspace.
To share the workspace as a repository:
Once your repository is created you may want to do a little house keeping. I suggest
adding the RemoteSystemsTempFiles
project to the .gitignore
file. Note: the
.metadata
file is added automatically by Eclipse.
You can ignore the RemoteSystemsTempFiles
by:
RemoteSystemsTempFiles
projectThe last stage is connecting the workspace repository to the remote repository we created earlier. Once you've switched to the EGit perspective:
You can then stage, commit and push changes in your projects and workspace.
When you first commit and push EGit will push the default branch master
to the remote and configure pull
ing this branch from remote repository.
Upvotes: 1
Reputation: 1323125
Follwing the User Guide, you would need to create the .git repo within your current project path:
If the .git
path is within the current project path, there is no reason EGit moves your files anywhere else.
Upvotes: 0