Git: how to make remote directory update when pushed to?

后端 未结 4 1734
醉话见心
醉话见心 2020-12-06 07:27

I want to use git to manage some data on a remote server, so I set up a non-bare repository there. I can push to it without problems, and the repository its

4条回答
  •  天涯浪人
    2020-12-06 07:48

    Git Version 1.9.1
    Ubuntu Server 14.04 LTS
    LAMP Server

    I set my LAMP server to update my working directory of my Git repo whenever one of my web developers pushes a change to the server. I noticed that the log would note the new commits, but would not update the working directory. Instead of doing this manually (git checkout -f) for every update, this can be set automatically to do so after a push has been received.

    1. In your ".git" directory, go into the "hooks" folder.
    2. Create a file named "post-receive" within the "hooks" folder with this content:

      #!/bin/sh

      # Update working directory after receiving a push from remote clients.
      # This should be directed at the git working directory.

      GIT_WORK_TREE=/var/www/dev_site git checkout -f

    3. Enable permissions to execute the file by typing "chmod +x post-receive" in the "hooks" folder.

    It will now update the working directory when commits are pushed to the Git repo. My site now shows the changes when I visit it in a browser.

    My working directory is /var/www/dev_site

提交回复
热议问题