Achim Mertens avatar

How I have set up Github with Eclipse

achimmertens

Published: 08 Nov 2021 › Updated: 08 Nov 2021How I have set up Github with Eclipse

How I have set up Github with Eclipse

Hello everyone,

I have a new installation of eclipse (Version: 2021-09 (4.21.0)) on my local PC. And I wrote my first Java code on it. But working without backup and versioning is dangerous, so I want to synch my project with Github.com.
There are several ways to achieve this goal, here I show what I did:

Precondition: Prepare SSH Key

On Github click on: Your account/Settings/SSH and GPG Keys:

grafik.png

I already had a ssh key, if you are interested to see how I did it, ask me, I have it in my private doku (# Create ssh key:) or follow the public Github docu.

So I already had an "id_rsa" file (with the private key) in my .ssh folder.
And also the default entry was set in Eclipse/Window/Preferences/General/Network Connections/SSH2:

grafik.png

Creating a new Java Project in Eclipse:

We start from scratch and create a new Java project:

grafik.png

grafik.png

grafik.png

grafik.png

Now we create in this project a java package:

grafik.png

grafik.png

Now let's create the first Java Class:

grafik.png

grafik.png

After creation, we put in some content:

grafik.png
We also can copy and paste classes from other packages (in my case I copied Event.java into the hamurabi package).

Short check, if it is running by pressing F11 (Yes it is):

grafik.png

So, now I have a local java project. The next thing is to synchronize it with Github.

Create a local and Github Repository

Ricghtclick on the project name and click on "Team/Share Project":

grafik.png

grafik.png

grafik.png

Now, we have a local Git Repository:

grafik.png

Now I click on Window/Perspective/open Perspective/Git:

grafik.png

Then I rightclick on the repository and choose "Commit":

grafik.png

In the right lower windows, We have to choose all the new files and add them to the index. After that, we have to type in a comment for the commit. Then let's commit and push:

grafik.png
I get asked for the remote destination. As it does not exist until now, we have to create it on Github:

grafik.png

Then we can take the URI. In my case I use the SSH URI, because I already have the SSH Keys implemented and it is much more convienent instead of typing in the password every time I push or pull:

grafik.png
And put it into the URI-Field:

grafik.png
(This is an old Screenshot. Please exchange "Test" with "Hamurabi")

After clicking on Preview it looks like this:

grafik.png

Now let's push:

grafik.png

grafik.png

Yeah - It has worked. The files have been pushed to Github:

grafik.png

Regards, Achim Mertens

Leave How I have set up Github with Eclipse to:

Written by

Love also your next but one and create more than you destroy.

Read more #programming posts


Best Posts From Achim Mertens

We have not curated any of achimmertens's posts yet. But you can encourage our curation team to review posts by visiting them regularly and by referring other readers. Because we give priority to frequently read content.

More Posts From Achim Mertens