These are the steps I took to enable me to be able to use GitHub with Eclipse on a Macbook. I'm using Eclipse Mars version, which comes with the Git plugin installed by default so I don't have to worry about that - my main challenges were in configuring Eclipse to communicate through mire firewall, and then top communicate with Git using SSH.
I needed to
- Configure Eclipse to go through the firewall
- Set up an SSH key on my Mac
- Register that key with Git
- Use Eclipse to Clone a Git Repository (Ii.e. download the code base on to the Mac)
Configure Eclipse to go through the firewall
Select Eclipse Preferences > General > Network Connections and fill in the proxy details - e.g.
Set up an SSH key on my Mac
This can be done at the command as described below, which I took from https://help.github.com/articles/generating-ssh-keys/. That page contains all the information that you need in order to generate the keys - for completeness I have screen-shot what I did and recorded below.
The ssh files are created in the user's .ssh directory - i.e. at ~/.ssh. You will be prompted for a file name, which you can ignore (i.e. just press Enter) and a pass phrase which you must remember! You also have to supply a unique identifier - I have used my email address in the following example
The sequence is as follows.
Enter the following command (substituting an appropriate value for the email address below)
ssh-keygen -t rsa -b 4096 -C "PEarle@premierfarnell.com"
You will be prompted for a file to save the key in - just press enter to use the default
You will be prompted for a pass phrase - enter something and remember what it is! This should be similar strength to a password - e.g. mixture of letters and numbers, case sensitive. You have to entere it twice to double check that you have typed it correctly.
The key will be gerenated and you will get some confirmation messages . e.g.
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/pearle/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /Users/pearle/.ssh/id_rsa.
Your public key has been saved in /Users/pearle/.ssh/id_rsa.pub.
The key is generated in your user .ssh folder. To check this type ls -l ~/.ssh e.g.
GBRMAC-12513:~ pearle$ ls -el ~/.ssh
-rw------- 1 pearle 1496817279 3326 21 Jul 11:13 id_rsa
-rw-r--r-- 1 pearle 1496817279 751 21 Jul 11:13 id_rsa.pub
Having created the key, it now has to be added to the SSH agent. This is done as follows ;
Make sure that SSH Agent is enabled
ssh-agent -s
Add the key. You will be prompted for the pass phrase (which you have remembered from above !).
ssh-add ~/.ssh/id_rsa
The contents of the key now have to be pasted into Git (see next section). To get ready for this open the public key file (e.g. less ~/.ssh/id_rsa.pub) and copy the contents to the clipboard.
Register the key with Git
Use your browser to log on to Git (e.g. https://github.com/) and then go to your Settings page (hint - click on your avatar image in the top right and select Settings from the dropdown). Select the SSH keys tab as shown below.
To add a new key, select the Add SSH key button in the top right. The p[age will extend to allow entry of a key Title (which can be anything you like) and the key value - paste in the contents of the id_rsa.pub file copied above. The key is then saved to you Git profile.
Use Eclipse to Clone a Git Repository
The final stage is to use Eclipse to connect to Git. My first step was to download the repository to my MacBook.
In Eclipse open the Git Repositories view (use Window > Show View to find this). You will see the following view (if you don't already have any repositories linked up) - the first thing I want to do is to Clone, so I select the second link.
Selecting Clone gives the following view. You will need to enter the SSH path to your repository in the URI prompt - the other fields will self populate when you do this. Make sure the Protocol is set to ssh. Note - the User/Password fields are not your Git user/password (this fooled me for some time!) This should be set as git. If you don't know the SSH path for your repository, go to the Git web page for your project, and on the right hand side you will see the 'Clone URL' panel - this may be defaulting to HTTPS, but there are links to show the SSH view.
Press Next and Git will retrieve the branches for your repository. You may be prompted for the SSH pass phrase that you used earlier at this point. Continue through the wizard and the code will download to your local environment.