Monday, September 21, 2015

Setting Up A GitHub Project in Eclipse


What is GitHub
In a very simple term GitHub is a repository where you keep your project code on cloud.



Why you need a GitHub account ?
Suppose you have two computers where you do your programming stuff. Unless you have a gitHub repository set in both the computers Eclipse workspace are not in sync, you can manually sync them by copying the workspace content from one computer to the other with some kind of USB drive (which is a dirty way). You will also find GitHub important when you what to set your project environment to a third computer or you want someone to contribute in your project at the same time follow the project structure you have defined.

You can set up Git Hub repository for you Eclipse java project in 3 ways
1. Through Git Hub Desktop
2. Through Eclipse Egit plugin and using eclipse UI menu
3. Through Eclipse Egit plugin and using git console <command line>

Here mostly I will be covering the point # 2

Before we begin the very first step would be to open a free git hub account. To open your free account please visit https://github.com/

STEPS TO CONFIGURE YOUR EXISTING ECLIPSE JAVA PROJECT AS A GIT REPOSITORY PROJECT


  • Download the Git Eclipse plugin from eclipse market place


  • On your already created eclipse project right click and select share project. Now your project becomes a git project without a head

  • Once you click on share project you see a screen like this, on the window select "use or create repository" And finally click create repository and finish.


  • Now your existing Java project is turned into a git repository but with no HEAD and will look like this



  • Next step is to right click on your project, select team and select "Show repository view.


  • Select Show in repository view.

  • On the next screen select create remote. Enter the default name as 'origin' .


  • Select to configure Push or Pull. 

  • Now configure Push and Pull for the repository.Enter the URI from the git repository you have created. Finally click Finish.





  • At this point you should be all set to push your content to the Git repository or to pull content from the Git repository
  • Point to remember here - Before you make a push request to the repository to check in your existing project content into the main branch, open the git repository account and create a readme / or any file into the repository. Once you are done with that from the Eclipse project make a Pull request to pull the new file you have created in the repository. Now you are ready to make a push request.
  • Before push make sure you commit the files you want to check in 






  • At this point you should be all set to make further commit and Push to main branch and fetch from main branch. To configure Eclipse with Git on 2nd computer first clone the repository and the follow the similar steps.





No comments:

Post a Comment