Git:推送到远程存储库时更新网站?
我有一个网站,每当我推送到远程存储库时我都想更新该网站。我有 svn 背景,但仍在尝试了解 git。
现在,我已完成以下操作:
- 在包含该网站的本地计算机上设置一个 Git 存储库。
- 将(裸)存储库克隆到我的 Web 服务器。
现在我有点卡住了。我可以将更改推送到服务器上的裸存储库,但我不知道如何在 www 目录中检出存储库的工作副本,并在将本地存储库推送到服务器时自动更新它。我可能需要一个钩子脚本,对吗?
相关问题,使用 Git 部署 PHP,部分答案我的问题,但我想知道脚本实际上在做什么。
I have a website that I'd like to update whenever I push to a remote repository. I am coming from a svn background and still trying to figure out git.
Right now, I have done the following:
- Setup a Git repository on my local machine containing the website.
- Cloned the (bare) repository to my web server.
Now I'm a bit stuck. I can push the changes to my bare repository on the server but I have no idea of how to checkout a working copy of the repository in my www directory and automatically update it whenever I push my local repository to the server. I'll probably need a hook script right?
Related question, Deploy PHP using Git, partially answers my question, but I'd like to know what the script is actually doing.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这对我有用,也可能对你有用:
以 Web 为中心的 Git 工作流程
This worked for me, it might work for you:
A web-focused Git workflow
我在 Caius Theory 网站上找到了一个非常好的(而且优雅的)解决方案
它基本上从一个裸存储库开始,并将工作树更改为 Web 服务器文件夹。之后,它在每次收到推送后使用接收后挂钩来更新工作树。一个优雅且易于遵循的过程!
除了该文章中的设置之外,我还添加了一个从网站位置到 git 存储库位置的软链接“.git”目录:
这样我可以通过登录到 Web 服务器上的另一个分支并使用“git checkout”来签出该分支。 “在网站文件夹中!
我还对 此处 中的 Python 脚本“ygit-push-all.py”进行了稍微修改使用不同的配置文件更新我的多台机器,它们都运行相同的框架代码。您甚至可以为每个服务器设置一个分支(如演示/开发)。
此外,我在全局 git 配置文件中添加了以下别名:
git push-all will update all 我的远程位置
git check-all will显示每个远程 master 分支所在的 rev
I found a very good (and elegant) solution for me on the Caius Theory Website
It basically starts with a bare repository and changes the worktree to the web-server folder. After that it uses a post-receive hook to update the work-tree after every push it receives. An elegant and easy to follow procedure!
Additional to the setup in that article I added a soft-linked ".git" directory from the website location back to the git repository location:
This way I can checkout another branch on the web-server by logging into it and using "git checkout " in the website folder!
I also used a slightly modification on the Python-Script "ygit-push-all.py" from here to update my multiple machines which all run the same framework code with using different config files. You could even setup a branch per server (like Demo/Development).
In addition I added the following aliases to my global git config file:
git push-all will update all my remote locations
git check-all will show me the rev on which every remote master branch is