Posted October 1, 2012 by Spyros in Ruby on Rails

How to Setup a Rails Project on a Remote Server with Git


Most times when i want to set up a new rails project, i am looking for the correct order of doing this. What i should do first, what i should do last, and so on. The procedure of correctly creating a new rails project on a remote server and then have the ability of making local changes, although very simple, needs to note it down somewhere. I will be presenting it here, in this short, but hopefully useful post. The whole procedure revolves around these 4 steps :

1) Setting a bare git repository on our remote server. The bare repository does NOT contain our project files, but the needed git files for the tracking of our project changes.

2) Creating a new rails project on our local machine.

3) Creating a non bare git repository on our local machine. The non bare repository is the one that actually contains our project files.

4) Setting our local non bare repository to be the master of our remote non bare repository.

Let’s begin :

<strong>1. Set a Bare Git Repository on Our Remote Server</strong>

mkdir railsclub.git
cd railsclub.git
git --bare init

<strong>2. Create new Rails Project on our Local Machine</strong>

rails new railsclub

<strong>3. Set a NON Bare Git Repository on our Local Machine(and committing initial import)</strong>

cd railsclub
git init
git add .
git commit -m 'initial import'

<strong>4. Set our non bare repository as the master of our remote bare repository</strong>

git remote add origin ssh://username@server_ip/path_to_repos/railsclub.git
git push origin master

<em><strong>NOTICE :</strong></em> If you made a mistake in specifying your remote origin, you can change it with the command :</pre>

git config remote.origin.url correct_remote_url