我们经常发布文档更新,此页面的翻译可能仍在进行中。有关最新信息,请访问英文文档。如果此页面上的翻译有问题,请告诉我们

Creating a GitHub Pages site with Jekyll

You can use Jekyll to create a GitHub Pages site in a new or existing repository.

GitHub Pages is available in public repositories with GitHub Free, and in public and private repositories with GitHub Pro, GitHub Team, GitHub Enterprise Cloud, and GitHub Enterprise Server. For more information, see "GitHub's products."

People with admin permissions for a repository can create a GitHub Pages site with Jekyll.

本文内容

基本要求

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 构建错误和阻止环境相关的漏洞。 To install Bundler:

  1. Install Ruby. For more information, see "Installing Ruby" in the Ruby documentation.
  2. Install Bundler. For more information, see "Bundler."

提示:如果您在尝试使用 Bundler 安装 Jekyll 时看到 Ruby 错误,您可能需要使用包管理器(例如 RVMHomebrew)来管理您的 Ruby 安装。 For more information, see "Troubleshooting" in the Jekyll documentation.

Creating a repository for your site

If your site is an independent project, you can create a new repository to store your site's source code. If your site is associated with an existing project, you can add the source code for your site to a gh-pages branch or a docs folder on the master branch in that project's repository. For example, if you're creating a site to publish documentation for a project that's already on GitHub, you may want to store the source code for the site in the same repository as the project.

If you want to create a site in an existing repository, skip to the "Creating your site" section.

Warning: GitHub Pages sites are publicly available on the internet, even if their repositories are private. If you have sensitive data in your site's repository, you may want to remove it before publishing.

  1. In the upper-right corner of any page, use the drop-down menu, and select New repository.

    Drop-down with option to create a new repository

  2. Use the Owner drop-down menu, and select the account you want to own the repository.

    所有者下拉菜单

  3. Type a name for your repository and an optional description. If you're creating a user or organization site, your repository must be named <user>.github.io or <organization>.github.io. 更多信息请参阅“关于 GitHub Pages”。

    创建仓库字段

  4. Choose to make the repository either public or private. Public repositories are visible to the public, while private repositories are only accessible to you, and people you share them with. 更多信息请参阅“设置仓库可见性”。

    用于选择机密或公开状态的单选按钮

Creating your site

Before you can create your site, you must have a repository for your site on GitHub. If you're not creating your site in an existing repository, see "Creating a repository for your site."

  1. 打开 Terminal(终端)Terminal(终端)Git Bash终端

  2. 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
  3. 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
  4. Change directories to the repository.

    $ cd REPOSITORY-NAME
    # Changes the working directory
  5. If you're creating a project site, decide which publishing source you want to use. If you're creating a user or organization site, you must store your site's source code on the master branch. For more information, see "About GitHub Pages."

  6. Navigate to the publishing source for your site. 有关发布源的更多信息,请参阅“关于 GitHub Pages”。

    For example, if you chose to publish your site from the docs folder on the master branch, create and change directories to the docs 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 the gh-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
  7. To create a new Jekyll site, use the jekyll new command, replacing VERSION with the current dependency version for Jekyll. For more information, see "Dependency versions" on the GitHub Pages site.

    • If you installed Bundler:

      $ bundle exec jekyll VERSION new .
      # Creates a Jekyll site in the current directory
    • If you don't have Bundler installed:

      $ jekyll VERSION new .
      # Creates a Jekyll site in the current directory
  8. Open the Gemfile that was created and follow the instructions in the Gemfile's comments to use GitHub Pages.

    Instructions for updating Gemfile

  9. Update the gem "github-pages" line so that the line looks like this, replacing VERSION with the current dependency version for github-pages. For more information, see "Dependency versions" on the GitHub Pages site.

    gem "github-pages", "~> VERSION", group: :jekyll_plugins
  10. Save and close the Gemfile.

  11. Optionally, test your site locally. For more information, see "Testing your GitHub Pages site locally with Jekyll."

  12. Add your GitHub repository as a remote, replacing USER with the account that owns the repository and REPOSITORY with the name of the repository.

    $ git remote add origin https://github.com/USER/REPOSITORY.git
    
  13. Push the repository to GitHub, replacing BRANCH with the name of the branch you're working on.

    $ git push -u origin BRANCH
  14. If you're using a non-default publishing source for a project site, configure your publishing source. 更多信息请参阅“配置 GitHub Pages 站点的发布来源”。

  15. On GitHub, navigate to your site's repository.

  16. Under your repository name, click Settings.

    Repository settings button

  17. To see your published site, under "GitHub Pages", click your site's URL.

    URL of your published site

    Note: It can take up to 20 minutes for changes to your site to publish after you push the changes to GitHub. If your don't see your changes reflected in your browser after an hour, see "About Jekyll build errors for GitHub Pages sites."

Note: If your site's source files are located in the default publishing source—master for user and organization sites or gh-pages for project sites—but your site has not published automatically, make sure someone with admin permissions and a verified email address has pushed to the default publishing source.

后续步骤

To add a new page or post to your site, see "Adding content to your GitHub Pages site using Jekyll."

You can add a Jekyll theme to your GitHub Pages site to customize the look and feel of your site. For more information, see "Adding a theme to your GitHub Pages site using Jekyll."

问问别人

找不到要找的内容?

联系我们