View website live after Git push [duplicate]

馋奶兔 提交于 2019-12-06 06:08:20
Ryan P

First off, you don't want to use a post-commit hook - that's a client-side hook. The server-side hook you want will be either post-receive or update (depending on whether you're using branches).

See: https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks

In your hook script, you should chdir to the server document root and run a git pull. Also, at the top of the script, make sure to include

unset GIT_DIR

otherwise git will confuse itself when you try to pull.

Assuming you create a post-commit post-receive or update hook on a machine with BASH, try something like this:

#!/bin/bash

cd /your/git/repository/directory
git checkout -f

...

A couple notes:

  • A little information about what is happening. When pushing to a remote repository, git does not automatically check out the new code. So, the post-commit hook needs to check out the latest code on the branch.
  • You may need to tell the git repository on your server to allow you to push to the checked-out branch. Running this command in the git repo on that server should do the trick:

    git config receive.denycurrentbranch false
    
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!