Getting started with Git, Github and eclipse plugin on OS X and Ubuntu

Despite all the elements being in place for git, github and eclipse to all work together well I couldn’t find any information on how to make it happen. I’ve been setting up a project on github for use at work so I needed to get all of the developers on the team up and running. I’ve now got git, github and eclipse working together on OS X, Ubuntu and windows. This post is about getting going on OS X and Ubuntu (any debian based distro should be the same). The windows setup is a bit more involved (think ssh hell) so I’m going to leave that for another post.

Install git

OS X

Depending on what you want there are two options, git on it’s own or git with svn support and bash completion. If you’re lucky enough to be just using git repositories and don’t care about bash completion then take option one, otherwise option two is probably what you want.

1) Git only

Download the latest dmg from http://code.google.com/p/git-osx-installer/downloads/list
Open dmg and run the installer
Complete installer using defaults
Check that it’s installed correctly opening a terminal and

git --version

2) Git +svn +bash completion

This method uses macports so you will need to install that first. The instructions to do this can be found at http://www.macports.org/install.php

Once you have ports installed type

sudo port install -u git-core +svn +bash_completion

Check that it’s installed with

git --version

Ubuntu

Ah ubuntu, it’s

sudo apt-get install git-svn

Check your install with

git --version

Signup with github

ssh setup

If you haven’t got ssh keys setup you’ll need to do that now. In a terminal

ssh-keygen -t dsa

Hit return for each option and you will end up with both private and public keys in your ~/.ssh directory

Create account

Go to http://github.com/plans and signup to whichever plan you want. On the signup screen there is an area to add your ssh key. To get this, in a terminal

cat ~/.ssh/id_dsa.pub

Once you’ve finished the signup screen you’ll be logged in and taken to your github home.

Create a repository

On the github home screen, next to “Your Repositories” click “create a new one”
Once you’ve filled the form out hit “Create Repository” and you’ll be taken to a page with some initial instructions. Follow these and you will end up with a local repository that is pointing to github as the origin.

You’re now setup with a github account and your first repository. So all that’s left is the eclipse setup.

Integrate with eclipse

Install plugin

The eclipse integration relies on the egit plugin. To read more about the project visit http://www.jgit.org/.
To install the plugin add the update site

http://www.jgit.org/update-site

Once you’ve added the update site open it and you’ll see that there are several builds available. I’ve been using the Release Build which seems to work well although the best option is likely to change. Check the box for the Integration Build and hit install and follow the wizard.

Checkout from github

The egit plugin assumes that you haven’t checked out the project yet so if earlier you checked out your new repository into your workspace folder you need to delete it so that egit can check it out itself and manage it. If anyone has found a better way of doing this please let me know.

From the “File” menu select “Import”
Select Git/Git Repository
You now need the git address for the repository you created in github.
To get this visit http://github.com
Click on your repository under “Your Repositories”
Copy Your Clone URL:
Back in eclipse paste into the import wizard
Change protocol to git+ssh
Hit next three times and eclipse download your repository
You’ll then arrive at the Import Projects screen
If you repository is currently empty then the list of projects will be blank
Egit will only checkout projects that have been previously been set up in eclipse
To remedy this we need to manually add a .project file to the root of your project
In a terminal

cd path/to/your/workspace/project
vim .project

Now paste in the following - changing the name to the name of your project

<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>test</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

Now save and exit, type
esc :wq return

Back in eclipse, in the import wizard, hit back and then next
You should return to the same Projects screen but this time your project will be available to select
Hit finish and you should now see your project checked out in your workspace

So there you go, git, github and eclipse all working in perfect harmony. Next up, using git-svn for all those pesky projects that are still in svn repos.


 
 
 

One Response to “Getting started with Git, Github and eclipse plugin on OS X and Ubuntu”

  1. Oliver Searle-Barnes » Getting started with Git, Github and Eclipse in Windows
    21. June 2009 at 08:41

    [...] Getting started with Git, Github and Eclipse in Windows [...]

Leave a Reply