Git local repositories with multiple local eclipse workspaces - eclipse

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.

Related

Creating a working copy of a GIT repo

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)

Eclipse Projects And Git

I used computer A via the Terminal to create a) create a git repository, b) add an index.html file to the repo, c) add a remote origin, d) push to the remote origin. All OK.
Then, i used computer B to clone that repository via Terminal. Then, I opened Eclipse (equipped with Egit), and created a new project in the folder that was created by the cloning process. Then I used Eclipse to push any changes to the remote origin.
Returning to computer A, I used Eclipse to create a project in the original repo folder, and then I attempted to pull from the remote origin, in order to get the changes that were pushed when using computer B.
Eclipse will not do it. It complains the I have items such as .settings, .project and similar and since they are not under version control it won't overwrite them by fetching files from the server. I had to manually delete those files (via Terminal) and then Eclipse worked as expected.
Please provide information on how to avoid this.
Should I create the local repo from within Eclipse and then push it to the remote origin, so that items such as (.settings) are under version control and (if so) how would that cause trouble to people cloning the repo and use different versions of Eclipse?
Should I gitignore those items?
Should I ask Eclipse to save its own affiliated files to another folder (not that i am aware how to do that, i only know that NetBeans does it)?
Looks like you didn't gitignored eclipse files.
Probably, when you commit/push via egit, you also commit and push those files you already had unversioned in your machine A, so git complains, because you are asking to override existing unversioned files.
I strongly recommend you to gitignore those eclipse files. You can see examples of .gitignore files in the github gitignore repo.
Hope it helps.
It complains because if you pull the changes from your remote it will overwrite your local files. That is the problem. The other answerer has right. You should better add all the eclipse project files and and target .settings and classpath to gitignore. You can use a global gitignore for your computers as well, before creating projects. You could use maven for example, then you can import your projects only from the pom.xml-s given in the git repository.
I use them the same. Egit and other guis are a bit too complex to work with. Git repositories can get easy in an inconsistent state where you should use the oldfashioned terminal to solve things. Like, rebasing, merging on conflicts. Gits learning curve is solid.
Now you can solve your problem if on the first computer save a backup of your original and clones your project later, after fixed it on the second. On the second git remove all this files, but use the --cached option to avoid deleting them. Before you do it so, check the help of git remove! after you have done this, put them into the .gitignore as filenames with wildcards. You can also use a global gitignore file in your user folder. Creating a .gitconfig file where you can specifiy the global ignore with the following :
[core]
excludesfile = ~/.gitignore_global
Than just create the .gitignore_global like this :
/nbproject
/bin
/build.xml
.idea
chess.iml
target/
bin
( This file is for idea and netbeans. you can add eclipse project files here )
You can have .gitignore files per project too. You can commit them to the repository, so on the next machine you do not have to do this again. The nicest way I think is having a dotfiles git repository, which is a git repo of your home directory and the dotfiles in it. I also use it for different windows and linux distros.
That's all. You should keep all of your configuration in a safe place. And source code management can do it. But do not commit private stuff to public a place! ;)
Oh I wanted to mention that, you can also have a .gitignore entry in your .gitignore file. That can be very useful when you do not want to touch a repository but need to add a gitignore to hide some stuff especially from the given repo.

Use CVS and GIT together in Eclipse

I already have a CVS and that cvs is used to share the source among other developers. But I need to keep a track of my source code changes separately. Moving the project from cvs to git is not practicable here.. and you may think that why 2 versioning controls. Any way I need to have a separate repository. I have tried git with eclipse. It is ok. I want to know how I can use both my personal git repository and cvs together in eclipse. (For example, when I commit my changes in eclipse, Team -> commit .. How can I separately commit to both cvs and git..and whenever I need to see the history in eclipse, separately git and cvs.. .Also when CVS server is not supporting, I can work with my local git repo as well. ) I need to handle all in eclipse IDE. Any one give any tutorial or links for my solution, it is highly appreciated.
You can have a git repo directly within your sources, but Eclipse would still be set on using CVS (and cannot show you both git and cvs commands at the same time).
That means you go on committing with CVS and Eclipse, but would need to commit (locally) in Git with an external tool (either a simple command-line session, or any GUI you want, like GitHub for Windows or SourceTree)
It actually is possible, if you create a dummy Eclipse project and designate the git repository at the workspace root (.git directory at same level as all projects in the workspace). This way when you make commits from this project, all projects in the workspace are its members and you can keep the members themselves connected to cvs.
You can create such repository by first creating the dummy project, and (Team->Share) sharing it via git using the Configure Git Repository dialog. Select “Use or create repository in parent folder” and explicitly remove the project folder from the "Create Repository" line after checking (checkbox) the project from the list of available projects.
After pressing "Create Repository" the project directory suffix will reappear, but remove it again before pressing Finish. In my version of Eclipse pressing Finish will hang, and I must terminate Eclipse to restart it.
After restarting the dummy project can be used to Commit files in all the other projects while the other projects remain connected to cvs.
Screenshot of “Use or create repository in parent folder” view when pathname has been entered by pressing "Create Repository" and then (corrected again before pressing) Finish.

How do I configure Eclipse to use an existing git repository with existing source code?

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

Egit, Eclipse folder structure

Let's say I have several projects in c:\dev\ and want to keep them there (this is my eclipse workspace)
What is the least inconvenient way to setup egit?
Turns out there is a bug in egit where you cannot create a git repo on an existing folder
You need to use msysgit to create the git repo on the command line, using git init
Then you can use egit as per the user guide