How To Add An Existing Git Project to Eclipse

Here's another quick set of notes for myself for posterity. I always clone and build a project on the command line before I import it into the IDE to begin hacking code. Right now I have to handle a hairy merge so I need a visual tool to make things a bit easier. For this purpose, I want to make Eclipse git aware so that I can use the visual diff in the IDE. Hopefully these notes will help out someone else, too.
For this situation I'm dealing with a Java project that uses git. First some quick items to set the stage:
- IDE:For Java development, my IDE of choice is the SpringSource Tool Suite (STS). If you develop Spring-based Java apps and you like Eclipse, you should really be using STS.
- SCM: The majority of projects I have worked with over the last few years use git for SCM. It is vastly superior to any other SCM tools I've used and documentation abounds for it, but it is a bit like a razor blade.
- IDE+SCM: The standard git tool for Eclipse is EGit
To make the Eclipse project git aware, follow these steps:
- Go to Window->Show View->Other
- In the filter field, enter the word git
- Select Git Repositories and click OK
- Click on the icon whose tooltip reads 'Add an existing local Git Repository to this view'
- Click on the browse button and navigate to the directory that contains the project source code
- Click the Search button
- Click OK
- Right-click on the project in the Package Explorer
- Go to Team->Share Project
- Select Git and click Next
- Check the box for 'Use or create Repository in parent folder of project - this should automatically find the .git directories
- Click Finish and let EGit complete the integration
After following these steps, the projects should be connected to their git repository. This allows you to handle the vast majority of git commands right from inside the IDE.
For more info about EGit, check out the EGit User Guide.
About Bruce Snyder
Bruce Snyder is a veteran of enterprise software development and a recognized leader in open source software. With over a decade of experience, Bruce has worked with a wide range of technologies including Java EE, Enterprise Messaging and Service Oriented Integration. In addition to his role as a senior software engineer at SpringSource, Bruce is also an Apache Member, a co-founder of Apache Geronimo and a developer for Apache ActiveMQ, Apache Camel and Apache ServiceMix. He is the co-author of Professional Apache Geronimo, Beginning Spring Framework 2 both from Wrox Press and is currently co-authoring ActiveMQ In Action for Manning Publications. Bruce also serves as a member of various JCP expert groups and is a recognized international speaker at industry conferences. Bruce lives in beautiful Boulder, Colorado with his family.
More About Bruce »NFJS, the Magazine
May Issue Now AvailableClient-Side MVC with Spine.js, Part 1
by Craig WallsOn Prototypal Inheritance, Part 2
by Raju GandhiMaking use of Scala Lazy Collections
by Venkat SubramaniamIntegration Testing Web Applications Using Gradle
by Kenneth Kousen