More recent versions of git have an alternative to the git symbolic-ref method that Chandru explained. This avoids having to use the lower level commands.

git checkout --orphan gh-pages
git rm -rf .
Answer from Arrowmaster on Stack Overflow
🌐
GitHub
docs.github.com › en › pages › getting-started-with-github-pages › configuring-a-publishing-source-for-your-github-pages-site
Configuring a publishing source for your GitHub Pages site - GitHub Docs
Your GitHub Pages site will always be deployed with a GitHub Actions workflow run, even if you've configured your GitHub Pages site to be built using a different CI tool. Most external CI workflows "deploy" to GitHub Pages by committing the build output to the gh-pages branch of the repository, and typically include a .nojekyll file.
🌐
GitHub
github.com › tschaub › gh-pages
GitHub - tschaub/gh-pages: General purpose task for publishing files to a gh-pages branch on GitHub · GitHub
Calling this function will create a temporary clone of the current repository, create a gh-pages branch if one doesn't already exist, copy over all files from the base path, or only those that match patterns from the optional src configuration, commit all changes, and push to the origin remote.
Starred by 3.3K users
Forked by 204 users
Languages   JavaScript 97.6% | Shell 2.3%
🌐
GitHub
gist.github.com › ramnathv › 2227408
Creating a clean gh-pages branch · GitHub
cd /path/to/repo-name git symbolic-ref HEAD refs/heads/gh-pages rm .git/index git clean -fdx echo "My GitHub Page" > index.html git add . git commit -a -m "First pages commit" git push origin gh-pages · Why do we need to do all this, instead of just calling git branch gh-pages.
🌐
_CLOUD
blog.ediri.io › how-to-create-a-github-gh-pages-branch-in-an-existing-repository
How to create a GitHub gh-pages branch in an existing repository
November 27, 2021 - Recently I wanted GitHub to serve my Helm chart via GitHub pages. So far so good, but I had already committed to the main branch. And I wanted a clean branch for my Helm repository. But with a little Git magic it is possible to get a clean branch. Let me show you, what I did: An orphan branch has no parents, means no git history when it is created. The history of the orphan branch is separate from other branches in the repository. git checkout --orphan gh-pages git reset --hard git commit --allow-empty -m "fresh and empty gh-pages branch" git push origin gh-pages
🌐
auto
intuit.github.io › auto › docs › generated › gh-pages
GitHub Pages Plugin - Intuit
The gh-pages branch is a special branch in your repository that you can use to store your built website. This branch will not track any of the source files for your project, but will have things like an index.html and all the other files needed to render your website.
Find elsewhere
🌐
W3C
w3.org › WAI › EO › wiki › GitHub › Repository_Creation
GitHub/Repository Creation - Education & Outreach
March 25, 2019 - Go to the main GitHub page of your repository. There, click on the Branch: master dropdown. In the Find or create a Branch… text field, enter gh-pages & press enter.
🌐
npm
npmjs.com › package › gh-pages
gh-pages - npm
Publish to a gh-pages branch on GitHub (or any other branch on any other remote). Latest version: 6.3.0, last published: a year ago. Start using gh-pages in your project by running `npm i gh-pages`. There are 1058 other projects in the npm registry using gh-pages.
      » npm install gh-pages
    
Published   Jan 02, 2025
Version   6.3.0
🌐
GitHub
gist.github.com › chrisjacob › 833223
Setup GitHub Pages "gh-pages" branch and "master" branch as subfolders of a parent project folder ("grandmaster"). · GitHub
Clone your "grandmaster" repository into the "gh-pages" folder (this will clone in the "master" branch), checkout the "gh-pages" branch, list the files (should have "index.html" and ".git") and then remove the "master" branch to avoid any confusion.
🌐
GitHub
github.blog › home › changelogs › build and deploy github pages from any branch
Build and deploy GitHub Pages from any branch - GitHub Changelog
March 22, 2025 - Repositories that use GitHub Pages can now build and deploy from any branch. Publishing to the special gh-pages branch will still work the same as it always has, but you can now choose a different branch in your repository as the publishing source.
🌐
GitHub
collectionbuilder.github.io › cb-docs › docs › deploy › gh-pages
Deploy on GitHub Pages from a Branch - CollectionBuilder
On the “Pages” page, under “Source” leave the dropdown button as “Deploy from a branch”. Under “Branch” use the dropdown to change from “none” to “main” (leave the folder option as “/root”), then click the “Save” button.
🌐
LinkedIn
linkedin.com › pulse › keeping-your-main-branch-gh-pages-up-date-same-time-brett-long
Keeping your main branch and gh-pages branch up to date at the same time:
September 27, 2023 - Make your changes to the main branch and push them to the remote repository. Checkout the gh-pages branch.
🌐
usethis
usethis.r-lib.org › reference › use_github_pages.html
Configure a GitHub Pages site — use_github_pages • usethis
The default of branch = "gh-pages" and path = "/" reflects strong GitHub support for this configuration: when a gh-pages branch is first created, it is automatically published to Pages, using the source found in "/".
🌐
Reddit
reddit.com › r/rust › psa: if you're using gh-pages to host your ci-generated documentation, make sure you don't store any history for that branch
r/rust on Reddit: PSA: If you're using gh-pages to host your CI-generated documentation, make sure you don't store any history for that branch
August 26, 2022 -

This is something we've been it with on the Smithay repository, and I'm thinking this might be of interest to others, so sharing what we found in case that helps. :)

For some time the Smithay git repo was becoming very slow to clone, and digging into this we realized it was almost 450 MB in size. It ended up that almost all of that space was taken by our gh-pages branch, on which our CI script uploads the api docs for Smithay and its public dependencies.

As it appears, Smithay is kinda hitting a few bad cases so that rustdoc output ends up pretty large: the target/doc/ folder we serve on github pages is ~220 MB in size. Keeping git history on such large content, generating huge diffs at each commit, really made the git repo blow up both in disk size and in processing time required to clone it.

As a first-step measure, we changed the CI script to overwrite the gh-pages branch at every run, rather than just appending a new commit. We use this gh-pages action, so it was just a matter of adding a force_orphan: true parameter.

Turns out that this improved the situation a lot: when it no longer needs to keep history, git manages to compress that 220MB of documentation very well, and now the whole Smithay git repo is only ~15 MB!

So if you're using gh-pages to host your documentation, you might want to check if you can have some similar gains on this side. :)

🌐
Gep13
gep13.co.uk › blog › how-to-create-gh-pages-branch
Gary Ewan Park - How to create gh-pages branch
In order for this to work, we need to create an orphan branch. More details on what this is, and why we need it, can be found here. In fact, everything that you need to complete this process is in that article, it just isnt' specific to my needs. So this is what I need... git checkout --orphan gh-pages git rm -rf .
🌐
HUGO
discourse.gohugo.io › tips & tricks
Simple deployment to GH Pages - tips & tricks - HUGO
January 3, 2017 - This is based on the assumption ... Publish from /docs folder on master branch As described in the GitHub Pages docs, you can deploy from a folder called docs on your master branch....
🌐
Frankel
blog.frankel.ch › refresher-github-pages
A refresher on GitHub Pages
June 16, 2024 - GitHub Pages rendered the root of the branch as a website. Travis works by watching a .travis.yml build file at the repository root. When it detects a change, it runs it. I designed the script to build HTML from Asciidoc sources and push it to the branch. Here’s the significant bit: after_success: # - ... - git push --force --quiet "https://${GH_TOKEN}@${GH_REF}" master:gh-pages > /dev/null 2>&1
🌐
GitHub
github.blog › home › changelogs › build and deploy github pages from any branch beta
Build and deploy GitHub Pages from any branch beta - GitHub Changelog
March 22, 2025 - Repositories that use GitHub Pages can now build and deploy from any branch. Publishing to the special gh-pages branch will still work the same as it always has, but you can now choose a different branch in your repository as the publishing source.