Git: Setting up with Eclipse

Here we are going to use Egit, an eclipse plugin. Lets start:

Installing Egit in Eclipse: EGit is already included in the latest Eclipse Release, so you do not need to install it. If you are using an older version you install using eclipse install new software wizard (Help -> Install New Software)

EgitEclipseInstallation

Configuring EGit

Every commit in EGit will include the user’s name and his email-address. Git configuration settings can be configured using the EGit configuration preference page but this configuration is not stored in the Eclipse preferences store but in git configuration files in order to ensure that native git sees the same configuration. To set these go to
Window->Preference => Team->Git->Configuration
EgitEclipseConfiguration

Enter key like ‘user.name‘ and corresponding value. Similarly for user.email. The username and email should be the same you use for your Git account, ie. your GitHub account.

Create a simple java project. I created a simple class with main having sysout. You will also require certain views which would be very handy in working like git repository, git staging, history. You can add them from Window -> Show View
EgitEclipseGitViews

Right now we are only working locally. We can make a local repository through the view , but lets make through out java project. Right click -> Team -> Share Project and select ‘Git’

EgitEclipseConfigureLocalRepoEgitEclipseCreateNewRepo

Now Finish. This will move the files from you eclipse workspace the git location. Notice the changes in your git repository view and the explorer :
EgitChangesAfterCreatingNewRepo

Since we have not committed anything it is coming as no head. Right click on project -> Team -> Commit
EgitFirstCommit

Usually we commit only java files and not class files. Select from the list accordingly and commit.
EgitEclipseViewAfterFirstCommit

Notice the master where we are actually building on. Now we want to push this to GitHub.

Go to your GitHub account. Create a new repository and copy the http url.

Now come back to eclipse in you ‘Git Repository’ view -> Remote -> Create remote
EgitCreateNewRemoteRepo

‘origin’ is the standard name, lets follow that

EgitCreateNewRemoteRepo1 EgitCreateNewRemoteRepo2

In the URI it will be your Github new repo URI. Host and repo path will be auto filled. Make sure the protocol used is https. You have to provide your username/password of your GitHub account. Note other protocol like sha can also be easily configured between your local and github. for now lets use https and click finish.

EgitCreateNewRemoteRepo3EgitCreateNewRemoteRepo4

Now we have to configure push ref mappings meaning which branch from the local is being pushed to which branch in remote etc. You can add those mapping manually or just click ‘Advance’ and map those accordingly. Check save specification in origin configuration. Finish and then save. Now your eclipse view :
EgitFirstPushToRemote

Now right click onto the red arrow and click push. Now check GitHub Repository.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: