A Short Tutorial on Eclipse/EGit/GitHub

I wrote this to help out some of my collaborators on our AI project for class, but I figure it might help some other people get started using version control.

Step 1: Get Eclipse

If you don’t want to work in Eclipse, that’s fine; you can access the source files directly without it. You will, however, need to look up how to generate SSH keys for your platform and how to set up Git on your own. GitHub has a nice tutorial after you sign up; so skip to step 2 and then take it from there.

If you do want to work with Eclipse, download the latest version here: http://www.eclipse.org/downloads/ and get the Eclipse IDE for Java Developers. Once you have it downloaded, extract it to someplace you will want to keep it, and double click on the eclipse icon to start it. We need to install the EGit plugin to use Git from Eclipse, so go to the “Help” menu item and click on “Eclipse Marketplace”. Search for EGit, and install it (it should be the only item that comes up). Restart Eclipse when it prompts you to.

Eclipse is a powerful development environment because it’s open source and has a ton of plugins for development; but that also makes it slow sometimes. Let’s make it go a little quicker. Go to the “Window” menu and click on “Preferences”. In the window that opens up, expand the “General” item, and go to “Startup and Shutdown”. This will show all the plugins that get started with Eclipse. Unselect all of them and click Apply”.

Ok, now that we’re in our settings panel, go to “Network Connections” and expand it. It’s under “General”. Click on “SSH2”, and move to the key management tab. IF YOU ALREADY HAVE A PUBLIC/PRIVATE SSH KEY GENERATED, SKIP THIS STEP. IT WILL OVERWRITE ANY EXISTING KEYS, AND YOU WILL NOT BE ABLE TO USE THEM ANYMORE. Otherwise, click on “Generate RSA Key…” It will create a public/private key for you; copy the public key from the text area and hold onto it. Don’t do anything more with Eclipse at this point; we need to set up our GitHub account before we go further.

Side Note:
If you already have a public/private key pair, you can open up the public key file (should be in /home/yourusername/.ssh/id_rsa.pub on Linux) and copy it for the next step.

Step 2: Getting Your Account Set Up

Ok, first things first: We need to set up a GitHub account. To do this, go to the main page at http://www.github.com and click on “Plans, Pricing and Signup” in the middle of the page. (It’s big and blue.) At the top of the next page, it has a free hosting plan above all the paid ones; click on “Create a free account”. Type in your username, email, and password (Generally, using your real name is a help in these kinds of things, since employers/future project leaders/current collaborators can tell who you are and what you’ve worked on) and click “Create an account”.

Cool! So we have an account. Next thing to do is set up our SSH key. Go to “Account Settings” at the top of the page click on it. On the left sidebar is an option “SSH Public Keys”, click on that. We’ll want to set up another key, so click on “Add another public key”. Give it a descriptive name in case you need to modify it, and paste the public key from Step 1 into the big box. Save the key, and you’re done! If you haven’t saved your key in Eclipse, go back and do that now. Click “Save Private Key”, and put it into the default folder. If you want to put a passphrase on it, I encourage you to do so; if your private key gets stolen the thief has your identity and access to any server that uses that key.


9 thoughts on “A Short Tutorial on Eclipse/EGit/GitHub

    • It really helps to have Eclipse open while I’m writing the walkthroughs. I try to keep the wording exactly to what you’ll see; I’m glad it helps! Thanks for the compliment!

  1. Great post. But, the issue I have is that I have *many* Eclipse projects that I want to “push” to Github and then use Github from that point for source control. Any tips on how to accomplish that?

    • It’s actually pretty straightforward to do that, luckily enough! First, right click on the project in Eclipse and select Team -> Share Project -> Git and select the project. If there’s already a Git repository there, it’ll allow you to checkmark the project; if not, select “Create Repository” and leave the default path. Click Finish.
      Now that EGit knows about your project, you can right click it again, go to Team -> Remote -> Push, and enter the details of your GitHub repository. The host is github.com, repository path is yourusername/yourrepo, protocol is ssh, user is git and password can be left empty; you’ll be prompted for your SSH private key password at the next window. Enter your password, select the branch you want to push (probably HEAD) in “Source ref” and the branch you want to push to in “Destination ref” (again, probably HEAD). Once you’re ready, hit Finish. It should push your changes and be available on GitHub! Unfortunately, ad-hoc setting of the remote tracking repository (aka, the one you pull/push to/from) isn’t supported yet by EGit. You’ll have to go to the command line to fix that if you want to keep the current project. Alternatively, you can just pull the source you just committed (you committed everything, right?) and create a new project from that based on the instructions in the tutorial. That will set up the RTB correctly.

      Hope that helps!

      • Yes, that does help. I need to unpack this statement however:
        “Unfortunately, ad-hoc setting of the remote tracking repository (aka, the one you pull/push to/from) isn’t supported yet by EGit. You’ll have to go to the command line to fix that if you want to keep the current project.”

        I am not sure what that means exactly (I am new to Git). Does that mean I cannot incrementally push the project to GitHub for “Safekeeping”? or does that mean I am not able to track the changes incrementally or?

        And what would be the command line “fix” for this?


      • It means that you’ll have to do the above “Push” sequence each time you want to send your updates to the remote repository. If you want to fix it from the command line on Linux, you’ll have to use the following commands:

        git remote add origin
        git config branch.master.remote origin
        git config branch.master.merge refs/heads/master

        This will let you push/pull using just git pull and git push to the remote repository; EGit should pick up on the configuration changes automatically and use them. Let me know if it doesn’t!

  2. Pingback: Eclipse and Github Tutorial « Missing Link

  3. Hey, I’m having a bit of trouble, I follow your instructions but when I get to the point where it’s asking me to File->Import then select Git, I don’t see a Git category. I only see General, CVS, Install, Plug-in Development, Run/debug, Team, XML.

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