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 Responses to “Adding Eclipse Project to Git”

  1. Dominic Mitchell Says:

    You probably want to say git tag -a otherwise other developers may not see your tag…

  2. digitaleagle Says:

    Thanks for the help Dominic. I have updated the post.

  3. svnsync « Linux Sagas Says:

    […] By digitaleagle I have decided to try svnsync instead of using git directly as I posted here and here.  Since I am a single developer, I was hoping it would be easier this way.  I found […]


Leave a comment