4

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.

3
  • What's wrong with your current setup?
    – ceejayoz
    Sep 4, 2013 at 20:43
  • i m not sure if its the best solution for this kind of problem ;)
    – inselberg
    Sep 4, 2013 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, 2013 at 1:16

3 Answers 3

5

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.

1
  • 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, 2013 at 23:26
2

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

2

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .