deployment - How to deploy a project using Git -
i figured out solution, feel there must simpler way of deployment, using git. solution that
- develop app git locally
- set git server
- clone local repository locally bare repository
- copy bare repository remote server
- set bare repository remote repository
- clone repository bare repository server (so have repo working directory)
- update bare repository pushing locally committed changes.
- update working directory pulling changes bare repo
it not simple solution, there may better ways use git deployment. tried use bare repository alone on server, , set work-tree variable in git config file other directory, didn't work: after first checkout, when updated bare repo , tried check out changes, seemed ok nothing happened in working directory. decided clone bare repository, cloned repo has working directory, , can updated git pull (this pull changes bare repo origin remote repository).
the big advantage of solution can fix code on server too, commit these changes, update bare repo, , can update local repository. advantage can clone project bare repo, , more participants can take part in development if have access server.
do know simpler way has above advantages?
i'm going describe accomplish that, may usefull you. i'm going give details new commers can helped in future.
i have server run personal experiments , used git deploy in simplest way found. it's done using hooks cames git , little shell script.
there go:
first: initialize bare repository in server. diference normal git repository lack of working tree (the project files , common stuff). have repository tree.
git init --bare
if @ bare structure going see this:
› git init --bare initialized empty git repository in /home/git/mysite/ › ls branches config description head hooks info objects refs
if closely @ hooks folder, can find interesting stuff:
daniel @ heavens-empire /home/git/mysite/hooks › ls applypatch-msg.sample post-update.sample pre-commit.sample pre-push.sample update.sample commit-msg.sample pre-applypatch.sample prepare-commit-msg.sample pre-rebase.sample
each 1 of files example of script can triggered after events. today looking @ post-receive event (it doesn't came in version.. don't know why). happens when push bare repository. can create , put little of shell beauty in it:
#shows file content daniel @ heavens-empire /home/git/mysite/hooks$ cat post-receive #!/bin/sh git_work_tree=/home/www/site git checkout -f
the git_work_tree going determine files of working tree i've pushed going be. it's have repo in folder , says tree in another.
i've copied scripts toy server, might should work you, changing apropriate work tree variable.
in local repository add bare folder remote repo. i'll use ssh make things simple. in case, make sure user use access has proper permissions on work tree folder:
git remote add mygitserver daniel@heavensempire.com:/home/git/mysite
every time make push, local git send commits. when server git repo receives , accepts them, fire post-receive script. work tree setted , permissions given, make simple checkout on folder app supposed run.
i hope usefull , may others. personaly avoid editting things on server. if find usefull have complete repo reflected in server, can use post-receive make clone/push , them checkout in repo. like:
cd /home/mysite git pull repo/folder masterorother
Comments
Post a Comment