Using git to deploy

Is there a way to deploy/deliver a git branch to different servers via SSH by using git ? Without setting up a git server, using services like github or connecting to the remote servers and pulling from the main server.

I need something similar to rsync or scp. My current quick and dirty solution is checking out, cloning to a tmp directory and rsyncing to deploy server.


First thing, as I've often been told, git is not a deployment framework. That stated, as Paul Gear said, the easiest way is by using remotes.

First set up the remote on the machine that will push. The target should be a bare repository.

git remote add server1 ssh://[email protected]/home/username/gitrepo

then select your branch on the source machine:

git checkout featurebranch1

Finally, push the data to your remote:

git push server1 localbranch:destinationbranch

Or you can set your push to upstream and push to whatever the upstream branch is.

git config push.default upstream

As I mentioned previously the remote git must be a bare repository to accept push like this.

Maybe using a bare repository isn't good enough. In that case, on the receiving side, you might want to do something when you receive the data, like maybe checkout the files to a different directory (the repo must remain bare, remember). You can do that using a post-receive hook by creating a script file in /path/to/bare/repository/hooks/post-recieve like so:

#!/bin/sh
GIT_WORK_TREE=/var/www/html git checkout -f

chmod it to executable. That will checkout the master branch into the specified directory.


You can push to a remote repo over ssh - this is what I use to update my github repos. Set up your ssh keys then add a remote in the form user@host:place/to/put/it.git


There are a complete solution that may help you to deploy your web application, it's named capistrano use it.

It is a simple ruby program that help lot when deploying application on many servers.