简体   繁体   English

Git和网站开发工作流程

[英]Git and website development workflow

My inquiries are specific and I understand that they can be subjective; 我的询问是具体的,并且我知道他们可能是主观的; I would appreciate any input. 我将不胜感激。

Here's what I was doing before git: 这是我在git之前所做的事情:

  • I run a PHP/MYSQL website 我经营一个PHP / MYSQL网站
  • I develop locally and test on WAMP 我在本地开发并在WAMP上进行测试
  • I FTP to a staging site dev.mywebsite.com 我FTP到暂存站点dev.mywebsite.com
  • Once I'm happy with all the changes, I FTP to the live site 对所有更改感到满意之后,我便通过FTP进入了实时站点

When I decided to start using Git: 当我决定开始使用Git时:

  • I initialized a bare repo on my hosting server 我在托管服务器上初始化了一个裸仓库
  • Created a post-receive hook to deploy to dev.mywebsite.com 创建了一个接收后挂钩,以部署到dev.mywebsite.com
  • I cloned the dev.mywebsite.com repo to a my local dev machine 我将dev.mywebsite.com存储库克隆到了本地开发机器上
  • I test code -> commit -> push to remote (dev site) 我测试代码->提交->推送到远程(开发站点)

Here are my questions: 这是我的问题:

1) There are a few files that I need them to remain different on local vs remote (these are mainly config files). 1)我需要一些文件以使其在本地与远程上保持不同(这些文件主要是配置文件)。 I am using --assume-unchanged for these files. 我正在对这些文件使用--assume-unchanged。 However, I read that doing 'git reset' would undo these so my first question: - Is there a better way to never change the config files when I push from local to remote? 但是,我读到做'git reset'会撤销这些操作,所以我的第一个问题是:-从本地推送到远程时,有没有更好的方法可以从不更改配置文件?

2) My workflow ends with me pushing to the dev site. 2)我的工作流程以我推送到开发站点而结束。 I am not sure how to proceed from there, and deploy my code to the live website in the most efficient and risk free way. 我不确定如何从那里继续,以及如何以最有效且无风险的方式将我的代码部署到实时网站中。

*3) A bonus question: Should I integrate github/bitbucket/etc.. into my workflow? * 3)一个额外的问题:我应该将github / bitbucket / etc ..集成到我的工作流程中吗?

Thank you 谢谢

Your approach is suitable only for very small development groups and small projects without need for complicated deploy. 您的方法仅适用于非常小的开发团队和小型项目,而无需复杂的部署。 But: 但:

1) Local vs Remote 1)本地与远程

I usually keep remote versions of config files in the repository and overwrite them on local with untracked files. 我通常将配置文件的远程版本保留在存储库中,并使用未跟踪的文件在本地覆盖它们。 The config loader then searches for override but does not fail if there is none. 然后,配置加载器搜索覆盖,但如果没有覆盖,则不会失败。

2) Dev + production 2)开发+生产

A rather easy way is that you keep a branch for development (dev) and branch for production (master). 一个相当简单的方法是保留一个分支用于开发(dev)和一个分支用于生产(master)。 Or as many branches as you want, in fact. 实际上,或者您想要的任意多个分支。 In the hook you get the name of pushed branch and decide on that where the new code will be copied to (in the simplest case). 在挂钩中,您将获得推送分支的名称,并确定将新代码复制到的位置(在最简单的情况下)。

The post-update hook may look like: 更新后挂钩可能看起来像:

for arg in "$@"
do
  if [ "$arg" == "refs/heads/master" ]
  then
    DEST="/path/to/production"
    git --work-tree=$DEST checkout -f
  elif [ "$arg" == "refs/heads/dev" ]
  then
    DEST="/path/to/dev"
    git --work-tree=$DEST checkout -f
  fi
done

3) External repository 3)外部存储库

If you want a backup or share with the world, yes, you should :) 如果您想备份或与全世界共享,是的,您应该:)

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

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