Connect Eclipse With Git: If you’re a programmer, then you know how important version control is. And if you don’t know what Git is, then you need to get on board because it’s about to change your life! Git is a free and open-source distributed version control system that is designed for speed and efficiency. It tracks changes in project files done by multiple developers so that everyone can stay up-to-date on the most recent developments. Eclipse is one of the most popular integrated development environments used by programmers which makes using Git super easy. So if you want to learn how to add your git credentials in Eclipse, read on!
Connect Eclipse With GitHub
In this blog post we are going to learn about:
- How to Set up and install Eclipse with EGit, and get a GitHub account
- Clone/fork an existing project from GitHub and import it into Eclipse
- Commit changes to a file in the GitHub project from Eclipse
|Post Type:||GIT Tutorial|
|Applicable For:||Freshers & Experience|
|Get Updates:||Join Our Telegram Group|
Installation and setup
If you want to get started with the development of software, you need to have Eclipse and EGit installed on your computer. You will also need a GitHub account so that you can access the code repositories.
Download Eclipse: First You have to download Eclipse from the official website of Eclipse If you have not downloaded it yet.
Install EGit Extension: If you’re using Eclipse, EGit is a plugin that allows you to interface with Git. Version control is becoming increasingly important, Nowadays EGit comes pre-installed with Eclipse downloads. If it is available within Eclipse then no need to follow the below steps.
If the EGit extension is not installed on your Eclipse then you can install it by following the below steps:
Open Eclipse and Click on Help Menu then Click on Install New Software, It Will open the available software dialog box like below.
Then Click on Add button, after that in the Name text box enter EGit, and in the URL text box enter https://download.eclipse.org/egit/updates/. Then Click Add in the dialog box.
Then It Will Display all the related extensions. There you need to select all the checkboxes and click next.
After that accept the terms and conditions and Click finish. Once you click finish the EGit install become successfully completed.
Create GitHub Account: During the GitHub blog post, we have already created a Github account. If you don’t have a GitHub account then for creating your GitHub account you can follow our detailed blog post where we have described in detail the GitHub account create process.
Create a repo in your GitHub account: After Creating an account on GitHub, Now you need to create a repository on GitHub. If you are worried about how to create a Git repository then you can follow our detailed blog post on how to create GitHub Repository.
Import your repository into Eclipse: the Final part is importing the repository to our Github account. So to Import your repository from GitHub you can follow the below steps:
- Open Eclipse, with EGit, installed
- In Eclipse, choose File, then Import
- In the dialogue that opens, choose Git > Projects from Git and click Next
If You have an existed local repository on your local machine then you can go with the existing local repository option. But for now, we are going to use the repository present on GitHub. So for that, you have to choose the Clone URI option.
Click on Clone URI and click Next.
Here you have to fill in the required information such as URI, Host, Repository Path, Username, and password.
You can get the URI from your Github Repository URL.
In the Host text box, you need to enter “github.com” because our repository is hosted on GitHub.com. and in the repository path, you need to enter the path of the repository.
The Full URL of our repository is looking something like this “https://github.com/softwaretestingo/javaprograms” but we need to mention the username and the repository Name. In This case which is “/softwaretestingo/javaprograms“
Note: When you enter the URI, then automatically it will collect the information of HOST and repository URL:
After that, you have to enter your GitHub username and password for authentication and Select the Store in the secure store checkbox. Then Click Next.
After Click Next it will connect with the GitHub Remote repository and in Return, it will display all the branches of the mentioned repository. Currently, we have only one branch available so the master branch is displaying.
Select the Branch and Click Next.
Here if you want to change the local repository location, then you can configure it here otherwise if you want to proceed with the default location then you can click next.
You can notice our remote is downloaded to our local machine. And you can click next
Currently, in our repository, we don’t have any projects. That’s why we are getting this screen. If you have any projects then those projects will be listed here. Here we don’t have any project so I am going to create a project here. So select the Import Using the New Project wizard and Click on the finish button.
Note: If there is any project on your repository then you will not get the below options.
On the Click Finish button, another new pop-up will appear there we select Java Project. If you want to create any other type of project then you can select any other project.
Select Java Project and click Next. On Click Next it will ask for your Project Information.
Click Finish Button. And the Java Project is added to Eclipse.
How to Push Changes to Remote Repository?
To Connect with Remote or Share your Project you have to right-click over your project and Choose Team – > Share Project.
Now we need to select the repository from the repository dropdown or you can click on create button to create a repository on the local machine.
Select the Project Checkbox and Click the finish button.
After clicking on the Finish button you can notice now the Local project directory is linked with the remote repository.
We have added some files and now before pushing those changes to the remote repository we need to commit those. So to commit You have to follow the below steps.
How to Commit Files Using Eclipse?
Right Click over the project — Team — Click on Commit
The Changes files will be displayed in the unstaged stanged area. You need to move those files from unstaged changes to the staged changes box and after that, before performing the commit operation you have to provide a meaningful commit message.
After that to commit the changes you can click on the commit button or you can click on the commit & push button to push the changes to the remote repository.
If you’re working on a project by yourself, the above workflow is all you need to get started with Git version control. However, things become more complex when multiple people are editing the same files at the same time. In these cases, Git’s branching and merging features come in handy. While we won’t be covering those topics in this tutorial, they’re both well integrated into Eclipse and EGit.
In This tutorial, we tried to cover how you can connect with the GitHub repository from the Eclipse IDE. If you still face any issues then you can let us know in the comment section and we will try to help with that.