making the world a stranger place

Site menu:

Archives

Links:

Github

Amazon Ad

Tags

Meta

Creating a Remote Git Repository

Having a local Git repository is great, it lets you keep versioned copies of your work, and doesn’t take up much space. But if you need to share your repository with someone else, such as with a development environment, you quickly find you need a simple way of keeping the repository up to date, and allowing access to other people. Email and thumb drives are soon not enough to keep up with the pace of development. What you need is a server to keep all the information in.

I’m going to show you how we have things setup, and hopefully guide you in your quest to have a remote repository that works for you.

Assumptions:

First off I’m going to assume you have a server setup somewhere, and that you have ssh and root(or sudo) access. This is written for FreeBSD, but the steps should be similar enough on pretty much any Linux or BSD distro.

  1. Create your local git project

    You’ll need to go ahead and create a repository on your local machine. Assuming your source code is stored in ~/rails/myproject…

    cd ~/rails/myproject
    git init
    git add *
    git commit -m “Initial commit”
    
  2. Move Your Repository to the Remote Server

    Next, since we don’t need the local working copy, check out the source from your local repository with the –bare option.

    cd ~/rails
    git clone --bare myproject myproject.git
    touch myproject.git/git-daemon-export-ok

    Now you can move this to the remote server, and stick it where you’d like it to be. I chose /usr/local/git, mostly because that’s where I have all my subversion stuff already. I also used Fugu to move the repository over, but you can use whatever you’d like.

  3. Install git on the server.

    Git needs itself available on the server when using SSH to pull repositories. I’m about to turn myself in a liar here, this step is probably not reproducible exactly as documented here on other OS’s. You’ll have to figure out how to install git on your particular distro. On FreeBSD, navigate to your ports directory (/usr/ports) and git is stored in devel/git. So on your server:

    cd /usr/ports/devel/git
    make install clean
    
  4. Other things

    To keep things clean, i created symlinks in the users home directories that needed access to the repository, and put the repository in a group called git, and gave group RWX permissions to the git directory.

     cd /usr/local/
    chmod -R 775 git/
    cd /usr/home/auser
    ln -s /usr/local/git/ git 
  5. Testing

    Now it’s time to make sure everything we just did worked.

    git clone ssh://user@remote.host.com/~/git/myproject.git
    cd myproject 

    All you code should be in the myproject directory, and you can use your repository just like you normally would.

Git is a nice tool, without all the extranious setup that subversion needs. It is fairly easy to get a remote repository running with Git. Do you have another way to host your Git repository, or did you do basically the same as I did, but slightly different? Do you know how to install Git on linux? Did I completely screw something up? Let me know in the comments.

Write a comment