Creating a working copy of a GIT repo - eclipse

I am working with Git/SourceTree/Eclipse. I am cloning a GIT repo outside of my Eclipse workspace. SourceTree is now pointing to this location.
There is no .project file in GIT. So in Eclipse I create a new dynamic web project and import my GIT repo (including the .git folder) into it. The project builds just fine.
Now this means that any changes I make in Eclipse won't be reflected in SourceTree because the GIT repo is essentially in 2 places. So I'd have to make another repo in SourceTree just to point to my Eclipse workspace.
I cloned the GIT repo outside my workspace because I heard that's best practice. But surely there's got to be a simpler way.
What is that simpler way?
Thanks for any helpful tips.

Since you imported the folder with the .git-folder into your workspace-folder, you could just use that directory for your development now. You no longer need the original clone.
However, I'm guessing cloning inside the workspace-directory is considered bad practice because it can slow down your Eclipse-project (see Is it better to keep Git repository inside or outside of Eclipse workspace?).
Probably cloning with EGit could make your life easier because it can point to a .git-folder outside your workspace-folder. (http://wiki.eclipse.org/EGit/User_Guide#Cloning_Remote_Repositories)

Related

Git local repositories with multiple local eclipse workspaces

I am starting to have a look at git before migrating from SVN.
I have read many helpfill questions here and some tutorials.
Normally, i have more than one eclipse Workspace created in my computer. Different "applications/programs" will use different eclipse workspaces.
When using git a local repo is either clone from a remote repo or created locally. The working tree of the local git repo is then refer from the eclipse workspace. This means that when i am actually changing things within eclipse i am changing them in the local git repo/ working tree.
So far is clear, but sometimes i have projects that are use in more than on application/program, thus in more than one workspace. What should in this case?
For what i have read i would thing that i would need to create a local git repo per eclipse workspace to avoid having two eclipse workspaces modifing the same local git repo/working tree which could cause all sort of trouble.
This means that, to be safe, every eclipse workspace should define a different HOME for the git repo?
Thanks in advance
You can create multiple workspace for the same git repo. use the
git worktree add <path of you worktree> <commit>
and modify the workspace safely.
git worktree --help
will give you detail info.

Why can't I use my workspace if its a Git repo with eclipse

I have a git repo that has a lot of test scripts in it. I started by setting this repo as my "workspace" in eclipse so I could make changes directly with eclipse and then just push them up to bitbucket once they are done.
Eclipse wont let me do this, I cant see anything in my work space and when I try to import the local repo to the workspace it tells me "Can't import project MavenTest from an existing workspace folder"
This doesn't make sense to me since I would have to make a separate workspace from my repo and then do the work into the workspace and manually copy it to the local repo and then push it up to bitbucket. Also pulling everything down will be a pain too since I'll have to copy any changes to my workspace. I defeats the whole purpose of version control.
Can someone please explain to me what I am doing wrong? I just want to work, push and pull all in the same directory.
Eclipse expects everything at the top level of its workspace directory to be a project, or otherwise content written by a plug-in through Eclipse's APIs. Any other content in the repository will be unusable and not importable as its location already overlaps the location of the workspace.
I would have to make a separate workspace from my repo and then do the work into the workspace and manually copy it to the local repo and then push it up to bitbucket.
Wrong. You're under the misconception that everything shown in the workspace has to physically live under the workspace directory, which is very untrue. They don't have to be there, they don't even have to be physical files.
Typically you will make Eclipse aware of the local clone using its Git Repositories View, and then use the view's context menus to import content from the repository's working directory as projects in the workspace (or using a Maven wizard provided through M2E). This import will not duplicate anything. You will still have one canonical location for your sources: your repository.
https://wiki.eclipse.org/EGit/User_Guide#Creating_Repositories

How to isolate Eclipse workspace from git local repository?

I installed EGit on Juno and created a Java project in workspace of Eclipse. Then I shared that project to Git. Then when I check the project's properties, I found that the project had been moved from its original workspace into Git local repository. When I make some changes in Eclipse editor, the changes are made on the local repository without commit.
How to isolate Eclipse workspace from git local repository?
(Well, my Eclipse workspace is ~/Documents/workspace, my git local repository is ~/git/myrepository1. )
The workspace is still in its original location outside of edit. It's the projects that have been moved into the git-controlled directories. Normally projects are created in the Eclipse workspace folder but you can override that default.
If you really want to isolate changes from git, you'll have to break git's control of the project, but you may still have to move the project contents back into your workspace. Unfortunately, the process of getting further changes back into git gets really messy.
I've found it unnerving at first the way git controls my eclipse projects, but after a while it does begin to make sense and is really a very powerful version control function.

Am I using EGit and Eclipse correctly when working with repositories?

I'm trying to set up EGit with Eclipse and I've used neither of them before. I understand the basics around Git and Eclipse is more or less just another IDE. The problem I'm having is setting up a reasonable work environment.
I have file-server at home which I want to use as a Bare repository which I push and pull changes to. To test it out I've done the setup locally.
I have a bare repository created through the Git Repository perspective.
I've cloned that repository into a local non-bare repository.
I've created a project in a subdir of the non-bare repository (is this the way to go? Is it possible to do have the project directly in the workspace with the .git folder within it? So far I've had a lot of trouble with it when trying to create an Eclipse project out of it. What is the proper way to do it?)
I've made some changes to this cloned repository and added the indexes, committed the changes and attempted to push the changes to upstream.
The thing is that no changes are made to upstream. Would someone like to explain the procedure in doing the push so that I'm not misunderstanding something? Or am I completely wrong on utilizing a bare repository instead of just working non-bare?
As mentioned in this tutorial, you create your Git repo right where your project is (ie your .classpath and .project files are).
Pushing to a bare repo is a good idea (see the links mentioned in "Git - pull & push - production server")
You need though to specify what you want to push:
Click at least on "Add all branch spec".

How to keep .git folder out of a Cloned Eclipse Project

Issue
After importing an Eclipse project from a cloned git repository, I make some changes and commit - and wtf? I get a ".git" folder added to the project, the whole shebang with the heads and refs and worst of all the whole object database gets added to the project, all files/folders having that little question-mark icon signaling that the files have not been added / are not yet tracked by git. This .git folder exists in the actual Working Directory (how does that even make sense?). You can imagine what an annoyance this causes when trying to use the "Synchronize" tool/view (which is supposed to make life easier for committing, you can see all the changes and changed files and diffs).
Question (tl;dr)
How to correctly import an Eclipse project from a cloned git repository? I don't want a .git folder showing up in "Team > Synchronize" when I commit, let the .git folder reside somewhere else outside of my project.
Additional Info
I'm on Windows 7 using Eclipse Indigo and Egit.
I am using Egit to clone a git repo from http://git.apache.org/ (the ofbiz project, to be exact) and in the wizard I choose the option to import an existing project from this newly cloned repo.
Yes I am aware of how little I may expect from Egit. In fact, if there are any alternative ways (external git tool? command line git for windows? other?) to use a git-tracked project in Eclipse which keeps the actual .git stuff out of the project, i'd gladly abandon Egit.
When you clone a git repository, the default behavior is to create a .git folder inside the root of the local clone. You can change the default behavior by setting the GIT_DIR variable:
Git docs says:
"GIT_DIR
If the GIT_DIR environment variable is set then it specifies a path to use instead of the default .git for the base of the repository."
Depending on which terminal you use, you could set it using setenv or export.
For example in a bash terminal:
export GIT_DIR='[path_to_git_directory]'
After setting the variable, you should be able to clone and the .git directory should show up at the specified directory.
I totally agree - I can't imagine it would ever be anyones intent to commit the .git folder!
And git/EGit knows that this is the repository folder of the project, so it should be easy to implement the appropriate exception - so that this folder does not become part of the synchronization.
I know the following does not solve your problem, but in cases where you control the way files are layed out in the repository, you could choose to have the Eclipse project folder not be the root folder of the repository, but rather a sub-folder.
This also allows you to have stuff in the repository that should not show up in Eclipse, or even have multiple Eclipse projects grouped in one repository (if you should wish to do so).