Commit e7986794 authored by Christoph Kepler's avatar Christoph Kepler


parent ebc02adc
How to git-hook
This repository is a short introduction into the git hooks to deploy.
First you need to create a new end point on the server you want to deploy to. This is done by creating a bare repository on the server.
Best is to create a directory ('mkdir' ENDPOINT) somewhere where the user of the server can access. For example his home directory. (Let's say it is /home/knechtrootrecht/project.git)
Than 'cd' into the directory and 'git init --bare'. A prompt like Initialized empty Git repository should apear.
Make sure that the correct branch is set. (stable for live/master for test ...) You can do this by setting 'git symbolic-ref HEAD refs/heads/stable' for example.
Use the Hooks
Put both files into the hooks directory in the repository. Make them executable (chmod +x HOOK) and make the changes within the files.
### pre-receive
Just change the branch and remote names in the error messages. This is optional but useful for the developers. The rest should remain as it is.
### post-receive
Change the GIT_WORK_TREE to the appropriate directory. This is the location the webserver can access and server the files.
### Advice
Make sure there is no .git/ within the webroot and that the correct access rights are set.
If you push with the user you probably need to change his primary group to www-data or use the setgid bit for the complete /var/www directory.
Local settings
The developers either need the password of the server user or their ssh pub-key on the server. (ssh-copy-id or something like that)
Within the repository on their local machines they have to add new remotes matching the server.
git remote add live user@server:path/to/directory
You can either use the relative path from the users home directory or the absolute starting with /
Name the remote like you set it within the pre-receive hook for the remote. (live, test, testserver ...)
Let's say the server user is knechtrootrecht and the webroot is already set.
> cd ~
> mkdir stable-project.git
> cd stable-project.git
> git init --bare
> cd hooks
> Copy the hooks
> vi pre-receive and make the changes
> vi post-receive and make the changes
> chmod +x \*-receive
> cd ..
> git symbolic-ref HEAD refs/heads/stable
The Hooks should be ready to push now.
You now have an empty repository within /home/knechtrootrecht/stable-project.git
Now add the remotes on the local dev machines.
> git remote add live knechtrootrecht@server:/home/knechtrootrecht/stable-project.git
> git checkout stable
> git push live
Than you should see messages that confirm that you have pushed correctly.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment