How to force GitHub Pages build?

前端 未结 9 1576
天涯浪人
天涯浪人 2020-12-12 14:41

Every GitHub repository can have (or be) a GitHub Pages website, that can be built with Jekyll. GitHub builds the site every time you push a new commit.
Is there a way t

相关标签:
9条回答
  • 2020-12-12 15:18

    From GitHub support, 2014-06-07:

    It's not currently possible to manually trigger a rebuild, without pushing a commit to the appropriate branch.


    Edit:

    As Andy pointed out in the comments, you can push an empty commit with the command:

    git commit -m 'rebuild pages' --allow-empty
    git push origin <branch-name>
    

    Edit 2:

    Thanks to GitHub Actions, it's fairly easy to trigger a daily publish: https://stackoverflow.com/a/61706020/4548500.

    0 讨论(0)
  • 2020-12-12 15:24

    This is doable as of v3 of the GitHub API, though it is currently in preview https://developer.github.com/v3/repos/pages/#request-a-page-build

    POST /repos/:owner/:repo/pages/builds
    
    0 讨论(0)
  • 2020-12-12 15:26

    Alternative Solution

    You may have received an email from GitHub telling you that Jekyll did not succeed at building your site when you pushed it to your gh-pages. If this is the case, you can try to force push to trigger another build.

    If you use a dedicated folder for the final website, let's say a public folder, you can try to rebuild your folder and add the folder to your commited changes. After that, you'll need to split those file into your gh-pages branch and force them to trigger another build even if the files did not change at all. The rest of the code bellow just removes the commits for the public folder for convenience and removes it from the local filesystem.

    Code

    git add public
    git commit -am ":bug: triggering another jekyll build"
    git push origin $(git subtree split --prefix public master):gh-pages --force
    git reset HEAD~1
    rm -rf public
    

    Tips

    If there are uncommited changes that are not part of the final site, you can stash them with the following command.

    git stash
    

    Then do the above command to manually force the Jekyll build and unstash them.

    git stash pop
    

    References

    • Online Git Manual
    0 讨论(0)
提交回复
热议问题