I use this for static and simple Sinatra based sites -- great for prototyping simple apps. Credit goes to http://toroid.org/ams/git-website-howto for the original idea.
If you don't know what this is, here's an example of how I deploy my website/app to a server:
# create/update/delete files in my site
git add .
git commit -m "description of the changes I made"
git push
# rinse and repeat
A lot of web designers or front-end'ers like to work with FTP to deploy their static sites. This is how I do it.
mkdir myproject.git && cd myproject.git
git init --bare
Then we define (and enable) a post-receive hook that checks out the latest tree into a directory where you'll serve your app from. I like to just create a ./www directory from within the bare git repo for simplicity:
mkdir myproject.git/www
cat > hooks/post-receive
#!/bin/sh
GIT_WORK_TREE=./myproject.git/www git checkout -f
chmod +x hooks/post-receive
If you don't have an existing git repo with your code in it, you can create one...
mkdir myproject && cd myproject
git init
echo 'Hola Mundo!' > index.html
git add index.html
git commit -m "The humble beginnings of my web site."
... or you can initialize a git repo in your existing code base:
git init .
git add .
git commit -m "initial commit"
After you've set up your local repository, the next step is to link up your local repository to your remote repository:
git remote add origin me@gitserver.com:[path to]myproject.git
git push origin master
That last command git push origin master
will "push" your local repo to the remote repo and also copy your code to myproject.git/www.
I usually use this workflow when I'm prototyping or building out sites. I usually don't bother with apache or nginx since sometimes it's easier to just use python to serve up simple static sites:
python -m SimpleHttpServer &
This will launch a simple HTTP server on port 8000. The important thing is that you'll need to keep this running in the background somehow -- and it's not trivial to turn it into a daemon. My simple solution to problems like this is to run this inside a screen session
I use Sinatra for lots of my small projects and this workflow works well for most of them. The process for Sinatra is the same for static sites, but instead of using python to serve up the site, I like using shotgun. Shotgun is used primarily for development so it's not ideal for running production sites on it, but it works well for my purposes. So, to run your sinatra app, all you need to do is run shotgun
inside a screen session:
shotgun -o hostname-to-listen-on [-p port]
The -o parameter is important to set since shotgun will only listen to 127.0.0.1 if you don't set it.