Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to change source branch in GitHub Pages

I have created a simple web site for GitHub Pages. The source of the site is in the "master" branch and the generated web site (what I want to see published) is under the "gh-pages" branch.

Branches

I was expecting to be able to change the source of the site in the settings. However, the setting is grayed out? I cannot change it (see screenshot below). What am I doing wrong? How do I switch to the "gh-pages" branch?

enter image description here

like image 616
Martin Avatar asked Oct 11 '16 13:10

Martin


People also ask

How do I change the source on GitHub?

Under your repository name, click Settings. In the "Code and automation" section of the sidebar, click Pages. Under "Build and deployment", under "Source", select Deploy from a branch. Under "Build and deployment", under "Branch", use the None or Branch drop-down menu and select a publishing source.

Why my GitHub Pages is not working?

Solution: Verify the publishing source and published URL from your repository's settings tab. Double check that you are using the correct URL by visiting your repository's Settings, and scrolling down to the GitHub Pages section. You should see the URL where your site is published.


2 Answers

Personal or organization sites are built from master. gh-pages branch is used to build sites for projects.

As far as I can see, you're using https://user-name.github.io/ url, this is a personal one, so that's why master branch is the default one.

See the documentation page

If your site is a User or Organization Page that has a repository named <username>.github.io or <orgname>.github.io, you cannot publish your site's source files from different locations. User and Organization Pages that have this type of repository name are only published from the master branch.

So the answer is No, you can not change it. You'll have to adjust your workflow and keep development in another branch (let's call it development) and merge to master when you're ready to publish.

UPD: It's 2020 out there, so as of July 31st GitHub Pages allow you to configure any branch to act as an old master

GitHub pages build branch selector

like image 102
Anton Sizikov Avatar answered Sep 30 '22 20:09

Anton Sizikov


FWIW, this is the setup I used for publishing a personal page (i.e. https://user-name.github.io) using Next.js and gh-pages:

  1. Create a different default branch in your repo to work in (e.g. develop)
  2. Build a static export of your site: next build && next export
  3. Put a .nojekyll marker file in the export directory: touch out/.nojekyll
  4. Upload the static export to the master branch: gh-pages -t -b master -d out

You can bundle these commands in package.json to get a convenient yarn deploy command:

scripts: {   ...   "build": "next build",   "export": "yarn run build && next export",   "deploy": "yarn export && touch out/.nojekyll && gh-pages -t -b master -d out"   ... 
like image 41
Rob van der Leek Avatar answered Sep 30 '22 21:09

Rob van der Leek