Posted on August 27th, 2008 at 9:40 pm.

This is part 3 of a 4 part series of setting up your systems to use Git.

So you’ve installed Git on your remote server and now want to be able to keep connect to a remote Git repository. This post will go through setting up a connection to two popular repository hosting providers, Unfuddle and Github. I should stress these sites provide instructions on how to connect to their repositories and so what I talk about here is already on these sites; I just wanted to have a complete set of instructions available in one place.

What you will need

  • SSH root access to your server (MediaTemple offer this though the Account Center)
  • An account on Unfuddle or Github
  • An SSH Keypair setup on your server (if you’ve not done this yet see Generating an SSH Keypair)
  • About 15 minutes of time

Method

Remote repositories use SSH Tunnels to transmit data between client and host. For this to work we need to register the SSH Key on our server with the remote repository. To find out what your SSH Key is you need to:

  1. Log into your server using SSH. Usually this is ssh root@your-domain.com
  2. Print the key to the terminal by entering the command : cat ~/.ssh/id_rsa.pub
  3. Copy everything that was just output to the screen to a blank document or your clipboard. It will be something like ssh-rsa <sequence of letters and numbers>== root@<your domain>

Now we have our SSH key we need to register it with our account on the remote repository. For Github this is on your “account page” under “SSH Public Keys”. On Unfuddle it’s on the “Personal Settings” page under “Public Keys”.

  • On Github choose to “add another public key”, whilst on Unfuddle choose “New Public Key…”
  • You’ll be asked for a title and a value. Enter a name in the title box which will identify this key clearly, for example “root on example.com”. In the value box paste the key pair you copied from the terminal window earlier.
  • These services now know who we are and we can authenticate with them. The next stage is to connect to the remote repositories.

    1. First thing you’ll want to do is find the Git Clone address. On Unfuddle this is displayed under the name of the repository on the Repositories page. On Github the address is called the Public Clone URL and can be found on the Source page for the repository. It will look something like git@something.unfuddle.com:something/project.git
      or
      git@github.com/username/project.git
    2. SSH into your server if your not in it any longer.
    3. Navigate into the folder which will contain your clone of the Git repository.
    4. Git cannot be cloned as a folder which already exists. If you want to clone the repository to a folder called “apples” you need to make sure the folder “apples” doesn’t exist already. In this case i’m going to clone my git repository into the folder httpdocs by using the command git clone <git clone url> httpdocs
    5. If this is the first time you’ve connect to the repository you’ll likely be asked to accept the RSA key fingerprint. Check the host name and IP that’s displayed and if your happy answer yes
    6. You’ll now be asked for the passphrase to your key. This is the phrase you entered when creating your SSH key pair before. This isn’t your SSH login password (unless you made them the same - which you really shouldn’t).
    7. If you get errors here such as fatal: The remote end hung up unexpectedly make sure your password is correct and that you’ve registered your SSH key with your provider

    You’ve now got a clone of the remote repository on your server. Now check the permissions are correct for your requirements. In my case I’ve cloned the repository into my web folder so I need to reset the permissions to those of my web account.

    Now, whenever you want to update the copy of the code on your server just run git pull

    In part 4 of this 4 part series I’ll talk about how I use Git to keep my production servers and easily publish updates.

    Posted in SysAdmin. You can leave a response, or trackback from your own site.

    Response Form