Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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.

share|improve this question
    
What's wrong with your current setup? –  ceejayoz Sep 4 '13 at 20:43
    
i m not sure if its the best solution for this kind of problem ;) –  inselberg Sep 4 '13 at 22:23
    
It would probably help to now more about your setup and what pain points you currently have. If rsync is doing the trick there may not be any reason to ditch it. –  ceejayoz Sep 5 '13 at 1:16

3 Answers 3

up vote 4 down vote accepted

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://username@server1.example.com/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.

share|improve this answer
    
I've also often been told that git is not a deployment mechanism, yet it often works really well as exactly that. I push to github from my laptop and pull from there on my servers (in cron) and it does the job nicely. –  Paul Gear Sep 4 '13 at 23:26

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

share|improve this answer

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.