Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deploying PHP website from Git repository

Tags:

git

deployment

I am trying to wrap my head around Git and deploying websites with (or without) it. I have been Googling and searching and reading, but can't find an answer to my specific case or concerns. I am still in the planning stages of doing this, but would like to get it right from the start and find a work flow that works for me. I will try to explain the situation as clear as possible:

I have a remote VPS that runs my live website on www.example.com and the development version on dev.example.com (they reside in /var/www/example/htdocs/ and /var/www/example/subdomains/dev/).

Development is run from a bare repository in /opt/git/example.git/. There is a master and development branch in the bare repo. Me and the other developer both have a clone of this repository on our local machine. We pull from the development branch and work from there. The idea is that dev.example.com has up to date code from the development branch and once that is properly tested, we merge into master, add a tag and update example.com (basically, this git flow).

The first approach I found on the Git IRC channel uses hooks to update repositories, but this feels very limitting and sometimes also unwanted, I'd like to run a command on the server myself after pushing, that updates the development environment. Another command (or shell script) would update the live site from the master branch after development has been merged). I also found Capistrano, but that seems a little over my head at the moment.

While reading, I found a lot of people suggesting to create two more clones on the remote: one for the live site and one for the development site, pulling in branches when necessary. This however also leaves the version control files accessible via the web, which is something I don't want. Ideally, I want a "clean" copy without any git files or folders.

I also found an approach using git archive, but running git archive from my bare repository only allows me to archive the master branch. I do this using the command git archive --format=tar HEAD | (cd /var/www/example/htdocs/ && tar xf -) in /opt/git/example.git/.

I feel like the git archive approach brings me closest to an answer, but I am limited by my lack of Git knowledge. Can I alter the command to use a branch instead of HEAD (when I tried using origin/master instead of HEAD, I got an error)? Is there anyone who can point me in the right direction?

like image 406
Bram Avatar asked Apr 06 '12 14:04

Bram


1 Answers

You can use any tree-ish (any branch, tag, sha1 hash etc) as an argument to git archive. You can't use origin/master since you are in the bare repo and it doesn't have an origin. You need to use the local branch names, e.g.

git archive --format=tar develop
like image 111
ralphtheninja Avatar answered Sep 30 '22 15:09

ralphtheninja