View website live after Git push [duplicate]

最后都变了- 提交于 2019-12-07 19:09:04

问题


Possible Duplicate:
Git Post-Receive Hook for Website Staging

I started learning Git today and I'm stuck on one thing.

When I push my local production repository to my remote staging repository, I would like to immediately be able to view my newly pushed files live. When I try to look for my files in my remote repository (via an FTP client), I can't find them.

Do I need to perform some advanced Git magic in order to achieve this (hooks?)? What is best practice for this situation?

Again, I'm new to Git and don't fully understand the concept yet. Maybe it's worth noting that I use a Webfaction Git application for the remote repository.

Edit: I saw this topic on SO, and I know how to create a post-commit hook but I have no idea what to put in the shell script.


回答1:


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.




回答2:


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
    


来源:https://stackoverflow.com/questions/9117812/view-website-live-after-git-push

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