top of page
Writer's pictureSandhya s

Github from eclipse using EGit

What is git?


Git is nothing but a version control system like svn which is used to track our local changes. Since git is decentralized unlike svn and is also open source, we don't need an internet connection to track and update all our changes (through commits).

If we want to share all our changes with our team, we update all our commits to a centralizer repository like Github or Bitbucket.


Important features in Git

  • Branching: Git allows users to create branches and work on their features independently so that the main branch is not affected and each team member can work on their own branch.

  • Merging: Once each team member is done with working in their own branch or they have completed the feature, they can merge the code into main branch to complete the flow of the code.

  • Collaboration: We can share all these changes in Github so that the team can view all the code and share their code as well.

  • Pull requests: A pull request is basically a request to merge the branch code into main branch. It is approved when there are no merge conflicts.


Common commands used git


git init: Initialize a new Git repository

git clone: Clone an existing Git repository

git add: Stage changes for commit

git commit: Save changes to the local repository

git push: Push changes to a remote repository

git pull: Both Fetch and merge happens from a remote repository

git branch: Manage branches and create new branch.

git fetch: Fetch all branches from Git remote

git merge: Merge changes from one branch to another


Many of us know how to use these commands in the command prompt or terminal.

But all these git commands can be done using Eclipse IDE as well which is way more easy to understand and execute.


Let us see how to do this eclipse with an example.


  1. In your eclipse, go to Help-> Install software.

    Select Install new software
  2. In the opened window, search for "egit" and select the option displayed as shown in the below picture.

  3. Select all the checkboxes under Git Integration for Eclipse and Click Finish




  1. Now We've installed egit for eclipse, Next we have to configure our user details, so that when we do a commit, our details will be shown in the github.

    Mac : Click Eclipse --> settings --> search "Git" --> click Configuration

    Windows :Window --> Preferences --> search "Git" --> Click Configuration




Configuring a new repository in Git

Once, we've added the email and name, lets see how to add a new git project.

  1. Lets Create a sample, maven project by clicking the Create a New maven project and giving a Group id and artifact id like below and click Finish.


  2. Next Right click on Project Name, Select Team --> Share Project


  1. Choose the Repository location by clicking the Create button. Click the checkbox near the project name and click Finish.


Now the new project has been configured in Git.


Cloning an existing repository from Github

  1. We can also clone a repository from github, by doing the following steps.

    Click File --> Import


  1. Choose Git --> Projects from Git --> Next


  2. Now click the Clone URI link and click Next


  1. Now place the repository path from github and paste it in the URI field and click Next


  1. Now Choose all the branches that you want and the Local Destination folder and Click Next

  2. Click Import as general Project and Click Finish


Adding Commits, Branches and Resolving Merge Conflicts:

  1. Commit:

    To add a new Commit, Right click Project --> Team --> Commit



    Now add the commit message and click commit and push



  2. Creating a branch:

    To create a new branch, Right click project --> Team --> Switch To --> New Branch

    Give a new branch name and click Finish



  3. Resolving Merge conflicts in eclipse:

    Resolving merge conflicts is easy with egit since eclipse provides a merge tool where we can see what the conflicts and it makes it easy to resolve them.

    1. Go to Right Click --> Team --> Merge



    2. Now choose which branch you want to merge with. Here I've chosen the latest Master branch from the remote repository and click Merge




    3. If there are any conflicts, a window will be displayed saying there are conflicts and also the file that has conflicts, a red symbol is displayed near the file in the project explorer. Also the file also shows the HEAD and refs in the file.



    4. Eclipse (egit) has a built in tool called Merge tool te help us resolve these conflicts.




    5. Now we can resolve the conflicts by changing the code and saving the file.



    6. After making changes to resolve the conflicts, We need to commit the file again by navigating to

      Team --> Commit and push. Now we have successfully resolved all the merge conflicts using egit.




      Conclusion

      We have learnt how to use EGit plugin in eclipse without using command prompt or terminal to execute git commands and track all code changes in Github.












42 views

Recent Posts

See All
bottom of page