GitHub Pages Import
ghp-import is a lightweight Python package designed to simplify the deployment of static content to GitHub Pages. It automates the process of copying built documentation or other static files to the `gh-pages` branch of a GitHub repository, then committing and pushing them. The current version is 2.1.0, and it has an infrequent but active release cadence, with the last major release in May 2022.
Warnings
- breaking ghp-import will DESTROY your `gh-pages` branch. It assumes that the `gh-pages` branch is 100% derivative of your source files. Any manual edits made directly on the `gh-pages` branch will be lost upon execution.
- gotcha By default, ghp-import pushes to the `gh-pages` branch. For GitHub User or Organization Pages (e.g., `username.github.io` or `orgname.github.io`), the content is served from the `master` (or `main`) branch. Pushing to `gh-pages` in this scenario will not publish your site.
- gotcha If your static site generator already produces complete HTML, GitHub Pages' default Jekyll processing can interfere. This might lead to unexpected rendering issues or files not being served correctly.
- deprecated Before version 1.0.0, programmatic usage of ghp-import was less straightforward and sometimes involved vendoring or modifying the script. Directly importing `ghp_import` as a Python function with keyword arguments was fully supported from version 1.0.0.
Install
-
pip install ghp-import
Imports
- ghp_import
from ghp_import import ghp_import
Quickstart
# Using as a command-line tool (recommended for typical use cases)
# Assuming your built documentation is in a 'docs_output' directory
# This command will create/update the gh-pages branch, add a .nojekyll file, and push.
ghp-import -n -p -f docs_output
# Using programmatically (if you need to integrate into a Python script)
from ghp_import import ghp_import
# Example: deploy 'build' directory, push to origin, include .nojekyll
ghp_import('build', push=True, nojekyll=True, mesg='Update GitHub Pages via script')