在Github Pages上创建网站的暂存和生产版本 [英] Creating staging and production versions of a site on Github Pages

查看:82
本文介绍了在Github Pages上创建网站的暂存和生产版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用Github Pages发布一个生产网站(例如,www.example.com)以及该站点的临时版本(例如,staging.example.com).

I want to use Github Pages to publish a production website (at, say, www.example.com) and also a staging version of the same site (at, say, staging.example.com).

我已经在Github中为生产站点设置了一个仓库(例如my-jekyll-website),创建了一个gh-pages分支,并将仓库的根目录下的CNAME文件设置为www.example.com. .效果很好.

I've set up a repo (e.g. my-jekyll-website) in Github for the production site, created a gh-pages branch, and set the CNAME file in the root level of the repo to www.example.com. Works great.

现在,还能将更改推送到staging.example.com的最痛苦的方法是什么?

Now, what's the least painful way to also be able to push changes to staging.example.com?

我尝试过的一件事是在Github上设置第二个远程仓库(例如my-jekyll-website-staging),然后将其作为远程添加到我的本地git配置中. 例外,效果很好,需要将存储库中的CNAME文件更改为staging.example.com才能正常工作.这样做不好,因为那时候我要部署到生产环境时,需要将CNAME文件改回www.example.com.不理想.

One thing I've tried is setting up a second remote repo on Github (e.g. my-jekyll-website-staging), then adding this as a remote to my local git config. Works great, except that the CNAME file in the repo needs to be changed to staging.example.com for this to work. Which is no good, because then when I want to deploy to production, I'd need to change the CNAME file back to www.example.com. Not ideal.

我研究过使用git 过滤内容驱动程序,但是如果我理解正确,那就是在本地修改文件,没有将文件的不同版本推送到不同的远程服务器.

I've looked at using git filter content drivers, but if I understand correctly, that's about modifying files locally, not getting different versions of a file pushed to different remotes.

我还考虑过根本不使用自定义域进行登台:即,仅使用username.github.io/my-jekyll-website-staging.不幸的是,然后我的相对于站点根目录的链接(例如/images/foo.bar)中断了,因为现在生产和暂存之间的baseurl不同.

I've also considered not using a custom domain for staging at all: i.e., just using username.github.io/my-jekyll-website-staging. Unfortunately, then my site-root-relative links (e.g. /images/foo.bar) break, because the baseurl is now different between production and staging.

推荐答案

从上面的评论中拉出:

[M]将登台git分支合并到生产中 分支并推送[.]您只需保持CNAME永久指向 到各自的存储库,但要分别操作存储库.

[M]erge the staging git branch into the production branch and push[.] You could just keep the CNAMEs permanently pointing to their respective repos, but manipulate the repos separately.

最初由 Jonathan Chan

Comment originally by Jonathan Chan

按照@JonathanChan所说的做:维护两个单独的分支,然后在每个文件中 hijack .这样,(对CNAME的)本地更改将不会提交到存储库.

Do as @JonathanChan says: maintain two separate branches, then hijack your CNAME file in each one. This way local changes (to the CNAME) will not be committed to the repository.

这篇关于在Github Pages上创建网站的暂存和生产版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆