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
gist.github.com › ramnathv › 2227408
Creating a clean gh-pages branch · GitHub
Well, if you are at master and you do git branch gh-pages, gh-pages will be based off master. Here, the intention is to create a branch for github pages, which is typically not associated with the history of your repo (master and other branches) ...
Discussions

gh-pages branch
Under /settings/pages you can set branch and subdir as GithubPages source. See https://docs.github.com/en/pages/getting-started-with-github-pages/configuring-a-publishing-source-for-your-github-pages-site More on reddit.com
🌐 r/github
4
2
May 30, 2021
github - Can I make the gh-pages branch of my git repository a mirror of the Master branch? - Stack Overflow
Why not have gh-pages be the master branch? No need to have two. Just set gh-pages as the default ... I ran through a bunch of my own tests. It doesn't seem like you need to go through the exact process they've laid out at http://pages.github.com/ in order to create the gh-pages branch. More on stackoverflow.com
🌐 stackoverflow.com
PSA: If you're using gh-pages to host your CI-generated documentation, make sure you don't store any history for that branch
There's an ongoing beta to make GitHub pages deployments from actions without pushing to a branch: https://github.com/actions/deploy-pages More on reddit.com
🌐 r/rust
38
326
August 26, 2022
My gh pages code and master code are not the same. Help
What "sublime text" are you talking about? Do you want to have your changes from gh-pages in the other brach master? Try git checkout master ; git merge gh-pages to merge your changes. More on reddit.com
🌐 r/git
8
5
June 17, 2017
🌐
_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
🌐
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.
🌐
Gep13
gep13.co.uk › blog › how-to-create-gh-pages-branch
Gary Ewan Park - How to create gh-pages branch
This is done by generating the documentation, and then pushing the result into a gh-pages branch on the GitHub Repository where the source code is hosted. This process is actually really simple, and it will be the topic of another blog post, but in order for it to work, we first need to create the gh-pages branch in the first place.
🌐
auto
intuit.github.io › auto › docs › generated › gh-pages
GitHub Pages Plugin - Intuit
{ "plugins": [ [ "gh-pages", { "branch": "docs", "dir": "./path/to/built/docs/website" } ] // other plugins ] } { "plugins": [ [ "gh-pages", { "branch": "docs", "dir": "./path/to/built/docs/website" } ] // other plugins ] }
Find elsewhere
🌐
Medium
missrhea.medium.com › hosting-with-github-pages-9062caa6a52a
Hosting With GitHub Pages - Rhea Rodrigues - Medium
March 5, 2021 - However, the publishing source for my GitHub Pages website must be able to read the contents in the ./public directory. To avoid this clutter on the default master branch I prefer to have these files on another branch. 4. Build and push to the remote gh-pages branch I'm developing the code for my website locally in the dev branch.
🌐
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.
🌐
Data Science for Everyone
matthew-brett.github.io › pydagogue › gh-pages-intro.html
Setting up a gh-pages branch — pydagogue 0.2 documentation
git-clean: git clean -fxd html: cd doc && make html gh-pages: git-clean html git co gh-pages git rm -r . git checkout HEAD -- .gitignore README.md .nojekyll cp -r doc/_build/html/* . # your sphinx build directory git stage .
🌐
GitHub
docs.github.com › en › pages › getting-started-with-github-pages › creating-a-github-pages-site
Creating a GitHub Pages site - GitHub Docs
You can add more pages to your site by creating more new files. Each file will be available on your site in the same directory structure as your publishing source. For example, if the publishing source for your project site is the gh-pages branch, and you create a new file called /about/contact-us.md on the gh-pages branch, the file will be available at https://<user>.github.io/<repository>/about/contact-us.html.
🌐
Sphinx tutorial
olgarithms.github.io › sphinx-tutorial › docs › 7-hosting-on-github-pages.html
Hosting on GitHub Pages | Sphinx tutorial
To host your docs on GitHub Pages, we need to enable GitHub Pages for our repo. To do that, we need to create a branch that only contains html files. We’ll name this branch gh-pages, as GitHub looks for this name and automatically starts hosting your documentation on pages.
🌐
24ways
24ways.org › 2013 › get-started-with-github-pages
Get Started With GitHub Pages (Plus Bonus Jekyll) ◆ 24 ways
December 18, 2013 - This tells GitHub that this is a special branch, and to treat the contents of it differently. Make sure you’re still in the christmas-recipes directory, and type this command to create the gh-pages branch:
🌐
Stephaniehicks
stephaniehicks.com › githubPages_tutorial › pages › orphan-ghpages.html
Creating Project Pages
Afterwards you can press ctrl-c to stop the process in the terminal. Otherwise, push everything to GitHub and you should be able to view or special Project Page at http://username.github.io/coolproject. $ git remote add origin git@github.com:username/coolproject.git $ git push -u origin gh-pages
🌐
GitHub
gist.github.com › chrisjacob › 833223
Setup GitHub Pages "gh-pages" branch and "master" branch as subfolders of a parent project folder ("grandmaster"). · GitHub
It works by cloning a copy of the repo into a shadow subdirectory named .gh-pages (which is added to .gitignore, too); this makes updating the gh-pages branch work seamless. Call ghpsd checkout to recreate the hidden .gh-pages folder, this clones locally and does not require network access. ... Hi! Very nice tutorial. I have a question: how can I create the two repositories via Github web interface and then do what your tutorial says (I don't want to use automatic page generator)?
🌐
npm
npmjs.com › package › gh-pages
gh-pages - npm
January 2, 2025 - Note that any files in the gh-pages branch that are not in the src files will be removed. See the add option if you don't want any of the existing files removed. ... The base directory for all source files (those listed in the src config property). ... /** * Given the following directory structure: * * dist/ * index.html * js/ * site.js * * The usage below will create a `gh-pages` branch that looks like this: * * index.html * js/ * site.js * */ ghpages.publish('dist', callback);
      » npm install gh-pages
    
Published   Jan 02, 2025
Version   6.3.0
🌐
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.
🌐
CommandMasters
commandmasters.com › commands › git-gh-pages-common
How to Use the Command 'git gh-pages' (with examples)
The command git gh-pages does not take any additional arguments. When executed, it operates within the context of your current Git repository. Here’s what this command does step-by-step: Branch Creation: It initiates a new branch named gh-pages ...