how do I deploy multiple branches to different directories via git push?

前端 未结 4 1206
礼貌的吻别
礼貌的吻别 2020-12-10 17:38

In production, I maintain two sites - beta and release. Each points to a different directory via a soft link (e.g.)

beta_public_html -> /home/scott/myapp/         


        
4条回答
  •  生来不讨喜
    2020-12-10 18:34

    The article Git push is worse than worsless has an interesting discussion about a similar issue.

    One of its solution and conclusion involves:

    • a bare repository on the production server
    • a cloned repository with a hook to pull what has been pushed into the bare one

    So in your case,

    • one bare repo on which you can push beta and release branches
    • two cloned repo 'beta' and 'release' with a hook to pull their respective branches from the bare repo.

    In short: one step: git push. No more link to manage (since the directory no longer represent a branch in Git, unlike SVN)


    Regarding the hook part, a post-receive hook in the bare repo could be all what you need

    See Git Tip: Auto update working tree via post-receive hook

    $ cd bare
    $ chmod +x .git/hooks/post-receive
    
    with a post-receive hook like
    
    #!/bin/sh
    cd ../../beta
    env -i git reset --hard
    cd ../../release
    env -i git reset --hard
    

    Note:

    the post-receive hook starts out with the GIT_DIR environment variable set to the repo/.git folder, so no matter what path you 'cd' into it will always try to run any following git commands there.
    Fixing this is simply a matter of unsetting the GIT_DIR.

    'env -i' does just that: it ignores the inherited environment completely and uses only the supplied variables and values.

提交回复
热议问题