简体   繁体   English

使用自动挂钩的网站开发上的Git工作流程:Git pull还是git clone?

[英]Git workflow on website development with automated hook: Git pull or git clone?

First of all thank you for your time reading this question. 首先,感谢您花时间阅读此问题。

I am currently researching on which Git workflow is most suitable for website development in the company I work for. 我目前正在研究我所工作的公司中哪种Git工作流程最适合网站开发。 There are different guides all over the net, but they mostly are conceptual. 网上有许多不同的指南,但它们大多是概念性的。 Please let me know if my way of implementing it is wrong: 如果我的实施方式有误,请告诉我:

1. The Concept 1.概念

Conceptually there would be 4 tiers, development, integration, staging, and production. 从概念上讲,将分为4个层,分别是开发,集成,分段和生产。 development tier is stored locally, integration is done with Git's help, production tier is located directly at public_html, and staging tier to preview the site before release is available at a protected directory __dev/staging (or better yet, __dev/[branch_name] ?). 开发层存储在本地,在Git的帮助下进行了集成,生产层直接位于public_html上,并且在发布之前可以在受保护的目录__dev / staging(或更好的是__dev / [branch_name])中使用暂存层来预览站点。 )。

2. Folder structure (staging & production tiers) 2.文件夹结构(暂存和生产层)

  • git 混帐
    • project.git (this is the bare repository of this website project) project.git(这是此网站项目的裸露存储库)
  • public_html 的public_html
    • __dev (password-protected directory) __dev(受密码保护的目录)
      • staging (this is like a copy of public_html used as staging tier) 分段(这就像用作分段层的public_html的副本)

3. Git setup within my local copy (development & integration tiers) 3.我本地副本中的Git设置(开发和集成层)

git remote add origin ssh://path_to_project.git
git branch staging

That way I got two branches to start, master and staging. 这样,我就可以启动两个分支,即master和staging。

When I do 当我做

git push origin master

The online version of the site should be updated without me having to ssh connect to the site. 该站点的在线版本应该更新,而无需ssh连接到该站点。 And when I do 当我这样做

git push origin [branchname]

__dev/[branchname] should be updated automatically. __dev / [分支名称]应该自动更新。

All the above could be done via git hooks. 以上所有操作都可以通过git hooks完成。 The reason of this automation instead of ssh connect and pull is this allow for faster development (otherwise if it takes more effort than ftp, what for :/. Do you agree?) 这种自动化而不是ssh connect and pull的原因是这样可以加快开发速度(否则,如果比ftp花费更多的精力,那么:/。表示什么呢?)

4. Hook 4.挂钩

This is where I got rather confused. 这是我很困惑的地方。

What I had in mind was either one of these two flavors: 我想到的是以下两种口味之一:

a. 一种。 clone and copy 克隆并复制

When I push to the site, the hook will clone bare repo to a temporary directory and copy it to public_html or __dev/branch depending on which branch I sent over. 当我推送到站点时,挂钩将克隆裸仓库到一个临时目录,并将其复制到public_html或__dev / branch,具体取决于我发送的分支。

b. reset and pull 重置并拉

When I push to the site, the hook will check if there is already a .git directory inside public_html or __dev/branch 当我推送到站点时,挂钩将检查public_html或__dev / branch中是否已经存在.git目录。

If none found, cd to that directory and git init, then git pull. 如果没有找到,cd到那个目录并git init,然后git pull。

If found, cd to that directory and git reset --head then git pull 如果找到,cd到该目录并git reset --head然后git pull

App installation using installatron or softaculous 使用installatron或softaculous安装应用

Sometimes I like to install the web app from installatron, and use that as a working base. 有时我喜欢从installatron安装Web应用程序,并将其用作工作基础。 Unfortunately there is no hook to automatically push to git after the installation done, so I have to connect to ssh and do: 不幸的是,安装完成后没有钩子可以自动推送到git,所以我必须连接到ssh并执行以下操作:

git add .
git commit -a -m "installed xxx app"
git push origin master

Then pull it in my local repository. 然后将其放入我的本地存储库中。

Conclusion and Question 结论与问题

What do you think about the workflow I had in mind? 您对我想到的工作流程有何看法? Is there anywhere I need to improve? 有什么需要改进的地方吗? Is the arrangement of branches okay? 分支机构可以吗? Which flavor is better 4.a. 哪种味道更好4.a. or 4.b., or is there another? 或4.b.,还是还有另一个?

Thank you. 谢谢。

Both 4a and 4b are commonly used. 4a和4b都是常用的。

I prefer 4b, as you have all the history of your repo available right in the production folder. 我喜欢4b,因为您可以在生产文件夹中找到所有回购历史记录。 You can see more at: 您可以在以下位置看到更多信息:

Regarding branches, start simple, and add those when needed. 关于分支,从简单开始,然后在需要时添加它们。
But don't forget that with a distributed VCS, you can push to an intermediate repo, which can notify a job scheduler like Jenkins of a new commit , in order to run some tests. 但是请不要忘记,使用分布式 VCS,您可以推送到一个中间存储库,该存储库可以向Jenkins这样作业调度程序通知一个新的commit ,以便运行一些测试。
If those tests pass, then you can push to the prod repo. 如果这些测试通过, 可以推送到产品仓库。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM