LinuxCommandLibrary

git-gh-pages

Publish Git repository content to GitHub Pages

TLDR

Create the GitHub pages branch inside the repository in the current directory

$ git gh-pages
copy

SYNOPSIS

git-gh-pages [options...] [path]

PARAMETERS

-r, --repo <url>
    Repository URL to deploy to (defaults to origin)

-m, --message <msg>
    Commit message (defaults to 'Deployment')

-d, --dir <path>
    Directory to deploy (defaults to current directory)

-a, --add
    Add untracked files to commit

-j, --nojekyll
    Create .nojekyll file to disable Jekyll

-b, --branch <name>
    Target branch (defaults to 'gh-pages')

-s, --silent
    Suppress output

-k, --keep
    Keep temporary clone directory

-R, --remote <name>
    Remote name (defaults to 'origin')

-u, --user <name>
    Git user name for commit

-e, --email <email>
    Git email for commit

-H, --no-history
    Omit Git history (shallow clone)

-n, --name <name>
    Alternative to --user for commit author

-f, --force
    Force push to overwrite remote branch

DESCRIPTION

git-gh-pages is a Node.js-based CLI tool designed to simplify deploying static websites or builds to GitHub Pages. It automates the process by cloning the target repository's gh-pages branch (or specified branch), synchronizing files from a local directory via rsync-like copying, committing changes with a custom message, and pushing back to GitHub.

Ideal for frontend projects, it handles common pain points like branch management, untracked files, and Jekyll settings. Install via npm globally, then run from your project root or build directory. It defaults to the 'origin' remote and 'gh-pages' branch, making it drop-in simple for most workflows.

Key benefits include no need for manual git commands, support for dotfiles, force pushes, and anonymous deployments. It's lightweight, fast, and widely used in CI/CD pipelines like GitHub Actions or Travis CI. Limitations include dependency on Node.js and git, plus GitHub repo permissions.

Countless developers rely on it for quick deploys without complex scripts.

CAVEATS

Requires Node.js/npm and git installed. Needs write access to GitHub repo. May fail on private repos without SSH/HTTPS setup. Not suitable for large repos due to full clone.

INSTALLATION

npm install --global git-gh-pages
Or yarn global add git-gh-pages

BASIC EXAMPLE

git-gh-pages dist deploys dist/ folder to gh-pages.
git-gh-pages -m 'v1.0.0' --nojekyll ./build

HISTORY

Created by Sindre Sorhus in 2013 as an npm package. Initially for personal use, gained popularity for simplifying gh-pages deploys. Version 1.0 in 2014; actively maintained with 2.x updates for modern git/Node compatibility. Downloaded over 1M times weekly on npm.

SEE ALSO

git(1), rsync(1), npm(1)

Copied to clipboard