git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: post-receive for web deployment

From
SMStephen Major <smajor@gmail.com>
Date
Dec 19, 2011, 02:42 UTC
Message-ID
<CALzTOm+sJHF_7WzjD7bCqAiAbQSV0A3hEX1KdWfFzV7-ePzX2w@mail.gmail.com>
In-Reply-To
<CALzTOmJUqzO8H5UxyFaodi98DBJtFvsbQsHsYh1U=Ggq3NRO5A@mail.gmail.com>
Hello,

I am having some difficulty understanding what I am doing wrong when working with git to deploy a website through the use of a post-receive hook on the remote.

Here is the script:
#!/bin/sh

staging_path="/home/user/domains/domain.com/public_html/staging" live_path="/home/user/domains/domain.com/public_html/live"

while read oldrev newrev ref do

    branch=$(echo $ref | cut -d/ -f3)
    # ***
    # update the live site
    #
    if [[ "master" == "$branch" ]]; then
        export GIT_WORK_TREE=$live_path
        git checkout -f $branch
        echo "Release has been pushed to production"
    # ***
    # we update the staging server with the latest push
    #
    elif [[ "develop" == "$branch" ]]; then
        echo "Resetting staging tree"
        export GIT_WORK_TREE=$staging_path
        git checkout -f $branch
        echo "Develop has been pushed to staging"
    fi
done
This is what we have done:

git checkout develop touch 1 2 3 4 5 6 git add . git commit -am "added some files" git push origin develop

checking the remote server now all files are found in: /home/user/domains/domain.com/public_html/staging

git checkout master git merge develop git push origin master

checking the remote server now all files are found in: /home/user/domains/domain.com/public_html/live

git checkout develop git rm 4 5 6 git commit -am "removed some files" git push origin develop

checking the remote server now files 4 5 6 have been removed from: /home/user/domains/domain.com/public_html/staging

git checkout master git merge develop git push origin master

checking the remote server files 4 5 6 are still found in: /home/user/domains/domain.com/public_html/live

Why is this happening? checking the local repo for master shows the files are removed there... pulling the latest from origin:master shows the files have been removed... but why were they not removed from the working tree like they were on the staging working tree?

well I think it has something to do with later commits and therefor the working tree of the live server could quickly become out of sync with the development tree

a quick test, lets checkout master again and perform the removes directly on it then push it back:

git checkout master git rm 1 2 3 git commit -am "removed 1 2 3" git push origin master

checking the remote server now files 1 2 3 have been removed from: /home/user/domains/domain.com/public_html/live

Okay weird so they remove when the commit happens directly on that branch and is pushed to the remote but they dont get removed if the removal happened on a different branch and is merged in then pushed to the remote....

anyone have an explanation or a workaround?
Next: Johannes Sixt
Message 1 of 4 in “Re: post-receive for web deployment”
  1. Stephen MajorDec 19, 2011
  2. Johannes SixtDec 19, 2011
  3. Sitaram ChamartyDec 19, 2011
  4. Stephen MajorDec 19, 2011

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.