We use Git as a tool for deploying a web application

    Hi, Habrosociety!

    Continuing the topic of using git hooks, I want to tell you about post-merge and post-checkout

    What do we have

    We have a web application that we are developing. We need to quickly and easily add changes to production

    What Git offers us

    post-merge - This hook is called by 'git-merge' after we execute 'git-pull' or 'git-merge' on the local repository. The hook will fail if we have conflicts with the merge.
    post-checkout - This hook is called by 'git-checkout', after we execute 'git-clone' or 'git-checkout'.

    What do we do

    The deployment mechanism will be something like this:
    1. Raise the git server. We translate all development to git. Pour the tested code into repository
    2. We write hooks that will do what we need to do after the deployment. In this case, the post-merge hook.
    3. If we want to deploy the working configuration on a clean server, then we write the post-checkout hook.

    For example, after the deployment we need to clean some folder and restart the Apache.
    /etc/init.d/apache2 stop
    find /path/to/folder -type f -delete
    /etc/init.d/apache2 start

    Put this script in .git / hooks / post-merge.
    We execute git pull and we have this script executed.

    Similarly for the post-checkout hook


    • Fast delivery of changes to production.
    • Automation
    • Centralized storage of a working web project


    • This scheme will not work if we create new branches by git checkout -b newBranch
    • This scheme will not work if we manually merge changes in the local storage.

    UPD: The goal is not to show a single and kosher kind of deployment, but how you can still use git hooks. And yes, I know about Capistrano, Vlad the Deployer, Chef (solo), Puppet and others

    Also popular now: