注意: 组织所有者可以限制从组织拥有的存储库发布 GitHub Pages 站点。 有关详细信息,请参阅“管理 GitHub Pages 站点的发布”。
Prerequisites
Before you can use Jekyll to create a GitHub Pages site, you must install Jekyll and Git. For more information, see Installation in the Jekyll documentation and "Set up Git."
建议使用 Bundler 安装和运行 Jekyll。 Bundler 可管理 Ruby gem 依赖项,减少 Jekyll 构建错误和阻止环境相关的漏洞。 要安装 Bundler:
Creating a repository for your site
可以为站点创建存储库或选择现有存储库。
如果存储库中并非所有文件都与站点相关,且要为存储库创建 GitHub Pages 站点,则能够为站点配置发布源。 例如,可以使用专用分支和文件夹保存站点源文件。
如果要在现有存储库中创建站点,请跳至“创建站点”一节。
- 在任何页面的右上角,使用 下拉菜单选择“新建存储库”。
- 使用“所有者”下拉菜单选择� 想要拥有存储库的帐户。
- 输入仓库的名称和说明(可选)。 如果要创建用户或组织站点,则存储库必须命名为
<user>.github.io
或<organization>.github.io
。 如果您的用户或组织名称包含大写字母,您必须小写字母。 有关详细信息,请参阅“关于 GitHub Pages”。 - 选择仓库可见性。 有关详细信息,请参阅“关于存储库”。
Creating your site
必须先在 GitHub Enterprise Server 上有站点的仓库,然后才可创建站点。 如果未在现有存储库中创建站点,请参阅“为站点创建存储库”。
警告:如果� 的站点管理员启用了公共页面,GitHub Pages 站点将在 Internet 上公开,即使该站点的存储库是私有的或内部的也是如此。 如果站点的存储库中有敏感数据,� 可能想要在发布前� 除数据。 有关详细信息,请参阅“为企业配置 GitHub Pages”和“关于存储库”。
-
打开终端终端Git Bash。
-
If you don't already have a local copy of your repository, navigate to the location where you want to store your site's source files, replacing PARENT-FOLDER with the folder you want to contain the folder for your repository.
$ cd PARENT-FOLDER
-
If you haven't already, initialize a local Git repository, replacing REPOSITORY-NAME with the name of your repository.
$ git init REPOSITORY-NAME > Initialized empty Git repository in /Users/octocat/my-site/.git/ # Creates a new folder on your computer, initialized as a Git repository
-
Change directories to the repository.
$ cd REPOSITORY-NAME # Changes the working directory
-
确定要使用的发布源。 有关详细信息,请参阅“为 GitHub Pages 站点配置发布源”。
-
导航到站点的发布来源。 有关详细信息,请参阅“为 GitHub Pages 站点配置发布源”。 For example, if you chose to publish your site from the
docs
folder on the default branch, create and change directories to thedocs
folder.$ mkdir docs # Creates a new folder called docs $ cd docs
If you chose to publish your site from the
gh-pages
branch, create and checkout thegh-pages
branch.$ git checkout --orphan gh-pages # Creates a new branch, with no history or contents, called gh-pages, and switches to the gh-pages branch $ git rm -rf . # Removes the contents from your default branch from the working directory
-
To create a new Jekyll site, use the
jekyll new
command:$ jekyll new --skip-bundle . # Creates a Jekyll site in the current directory
-
Open the Gemfile that Jekyll created.
-
Add "#" to the beginning of the line that starts with
gem "jekyll"
to comment out this line. -
Add the
github-pages
gem by editing the line starting with# gem "github-pages"
. Change this line to:gem "github-pages", "~> GITHUB-PAGES-VERSION", group: :jekyll_plugins
Replace GITHUB-PAGES-VERSION with the latest supported version of the
github-pages
gem. You can find this version here: "Dependency versions."The correct version Jekyll will be installed as a dependency of the
github-pages
gem. -
Save and close the Gemfile.
-
From the command line, run
bundle install
. -
Optionally, make any necessary edits to the
_config.yml
file. This is required for relative paths when the repository is hosted in a subdirectory. For more information, see "Splitting a subfolder out into a new repository."domain: my-site.github.io # if you want to force HTTPS, specify the domain without the http at the start, e.g. example.com url: https://my-site.github.io # the base hostname and protocol for your site, e.g. http://example.com baseurl: /REPOSITORY-NAME/ # place folder name if the site is served in a subfolder
-
Optionally, test your site locally. For more information, see "Testing your GitHub Pages site locally with Jekyll."
-
Add and commit your work.
git add . git commit -m 'Initial GitHub pages site with Jekyll'
-
Add your repository on your GitHub Enterprise Server instance as a remote, replacing HOSTNAME with your enterprise's hostname, USER with the account that owns the repository, and REPOSITORY with the name of the repository.
$ git remote add origin https://HOSTNAME/USER/REPOSITORY.git
-
Push the repository to GitHub Enterprise Server, replacing BRANCH with the name of the branch you're working on.
$ git push -u origin BRANCH
-
配置发布源。 有关详细信息,请参阅“为 GitHub Pages 站点配置发布源”。
-
在 GitHub Enterprise Server 上,导航到站点的仓库。
-
在存储库名称下,单击 “设置”。
-
In the left sidebar, click Pages.
-
要查看您已发布的站点,请在“GitHub Pages”下点击您的站点 URL。
注意: 对站点的更改在推送到 GitHub Enterprise Server 后,最长可能需要 10 分钟才会发布。 如果一小时后仍然在浏览器中看不到 GitHub Pages 站点更改,请参阅“关于 GitHub Pages 站点的 Jekyll 生成错误”。
注意:If站点尚未自动发布,请确保具有管理员权限和经验证的电子邮件地址的人员已将站点推送到发布源。
Next steps
To add a new page or post to your site, see "Adding content to your GitHub Pages site using Jekyll."
您可以将 Jekyll 主题添� 到 GitHub Pages 站点,以自定义站点的外观。 For more information, see "Adding a theme to your GitHub Pages site using Jekyll."