Adding Eclipse Project to Git

I did an earlier post where I did this, but I felt like it was sloppy.  Also, I did not add files to be ignored.  So, here is how to add an existing Eclipse project to Git:

Step 1:  In a terminal, change directories to your Eclipse workspace and project (assuming it is called my-project)

cd ~/workspace/my-project

Step 2: intialize the repository

git init

Step 3: add any files you want to ignore — consider any test data that might contain real production data and also consider connection information

vi .git/info/exclude

Assuming you have an Apache Derby database called db, you would exclude all of the database and the log with the following two lines:

db
derby.log

If you want to exclude Eclipse specific files, you may choose to add the following two lines:

.classpath
.project

Step 4: Add your files to your new Git repository

git add .

Step 5: Commit your files to the repository

git commit -m "My-Project inital code"

Step 6: Tag your code with a version

git tag v1.0

Update: You may want to tag this way so other developers see your tag (thanks Dominic):

git tag -a -m "GIT v1.0" v1.0

Now, your git repository is created and contains the code from your Eclipse project.

Resources

3 thoughts on “Adding Eclipse Project to Git

Leave a Comment

Your email address will not be published. Required fields are marked *