Wednesday, February 11, 2015

Eclipse GIT beginners tutorial - Part I



Goals:
To get a local GIT repository working with Eclipse project quickly. The idea is to have a GIT source control backed Eclipse project so you can make commits and get into the habit of using the GIT's features of branching, tagging, etc.
And at some point of time if the project needs to be shared then adding a remote and sync'ing (push) with it.

Note: I didn't find a simple guide when I searched for it and have decided to write one for those in search of such a setup.

(And thanks to the 'wink' project debugmode.com, I have used it for several years. It is simple and good enough for most captures).

Starting from the top

  • Create a new project. I created a Java project in eclipse, but obviously it can be whatever you choose. 
 

  • Name your project. Location of the project at this time is not relevant since it will end up being moved into the GIT repository later.


  •  Optional : create some code etc.

 
  • Share the project: Right click the Project then Team> Share Project

  • Select GIT
  • Create a GIT repository.
  • Note that you will be creating one repository per Eclipse Project. You can obviously have more than one project in one Repository but that messes with the commits and tagging of a single project related activity and tracking etc.

  • All set to make the move to a GIT repo.
     
  • Check the properties of the project to identify where the project files are located.
  •  Note that it has been moved into the GIT repository location. IMP NOTE: Any open files while you were making the move into GIT are now stranded since they are still open from the original location. So close those files and re-open them in Eclipse.








  • We make a spelling mistake and commit the change. 
  • Commit the change


    • History of commits shows the activity.
    • Oops we just noticed the error 'nmae' instead of 'name'.
    •  Fix the spelling and commit again. I prefer to commit one file at a time with notes on the changes for each file. You could have committed any number of changes in any number of files with a single commit comment. That is definitely helpful when changes are fairly obvious.
    • Note: At the time of committing a change, you can double click on any file in the commit box and Eclipse will bring up a compare window showing comparison between current and previous commit history.

    • You can compare with older commits for a file now using GIT functionality. And identify what changed.