Pre-push and post-push hooks involving remote checkout

老子叫甜甜 提交于 2019-12-17 20:32:12

问题


I have a remote repository for a website which I am developing on my local machine.

I use git flow for neat branching model, so my branches are:

  • master
  • develop
  • feature/one
  • feature/two
  • release/one
  • release/two
  • etc

The simplified work flow is as follows:

  • make changes in develop
  • push develop to backup server
  • checkout to master
  • merge master with develop`
  • push master to live server

What I want to achieve, is that when I push master branch to live server, I should be able to instantly see changes when accessing website by URL.

The problem is that I can't really push master, because it is checked out on live server.

Can I write a pre-push hook which will do a checkout to dummy branch on remote, and a post-push hook which will do a checkout back to master? The point is that these hooks involves execution of git commands on remote and I'm not sure how to do this.

Would appreciate any examples very much!


回答1:


You should push to master on a bare repo.

Then a post-receive hook can checkout that bare rpeo on your live server.

cd /path/to/bare/repo.git
GIT_WORK_TREE=/path/to/live/server git checkout -f


来源:https://stackoverflow.com/questions/20311851/pre-push-and-post-push-hooks-involving-remote-checkout

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