Hosting on github

Hi I have a probably simple question. I started to develop a page I want to publish on github as github pages.
Everythin works fine so far, but I suppose it can be done in a better way.
At the moment I published the local content of the public folder to my username related github pages directory.
So the page is generatd directly from master branch.

If I follow the instruction “hosting on github” there is written the build action has to be configureds in the file .github/workflows/gh-pages.yml. If I use this method I have to push the full repository to github and the page is generated with the github action I defined in the gh-pages.yml
But what is the puplishing directory, and where is it located? I read it should be named as docs/ or ./public and this folder can be selected as github pages branch.

This is the documentation I refer to: Host on GitHub | Hugo

Sorry for this long text my bad english and these stupid questions, but I have not worked with github until now and I am new to hugo. May be you can help me :slight_smile:
Regards Johannes

It’s not really about better way or worse way.

GitHub Pages is one solution. Many of us deploy with Netlify as we gaining some useful things that GitHub Pages lacks like _redirects and _headers.

You can also try CloudFlare Pages as they are available for all now and they also added long awaited _redirects.

Pros hosting on netlify is also this, that you not pushing public folder and just everything rest. Netlify is building using Hugo script a page for you.

Maybe I don’t answer your question, but for simplicity try push to GitHub all apart /public

Use below locally (I include _gen/assets as prefer them to be generated before publishing, as saving me time on Netlify build).

echo ".DS_Store \npublic/ \nresources/ \nresources/_gen/assets/" >> .gitignore

My typical initial procedure (further I using GitHub App)

echo ".DS_Store \npublic/ \nresources/ \nresources/_gen/assets/" >> .gitignore
git init
git remote add origin https://github.com/username/yourrepo.gi
git pull origin master
git add .
git status
git commit -m "initial commit"
git push -u origin master

Hugo builds a site into a public directory by default. (We can define the name by publishDir in a config file.) We call such a directory publishing directory. Since thoes files or directories (HTML, CSS, JavaScript, Images, and so on.) are generated contents, we do not need to put those under Git control. A publishing directory will be generated on GitHub Actions runner each commit automatically.

config.toml

baseURL = "https://USERBANE.github.io/"
title = "My Blog"
theme=""
publishDir="docs"  # default is "public"

git command

git init
git remote add Github  https://github.com/username/repoName.git
hugo --minify --gc      # copy the "docs/"  (since your config.toml is set ``publishDir="docs"``) other command you can query it from ``hugo --help``
git checkout -b gh-pages  # create a new branch gh-pages, and paste the "docs/" at this branch
git commit -m "commit message v0.0.0 or something you like"
git push Github gh-pages # or push all    ``git push Github --all``

Creating gh-pages is unnecessary but I will encourage you to split the source and build with two-part.

Your gh-pages are clear that only exists a directory (docs/) you can reference here

and then setting the Github pages, see below


Github Action is something for you doing CI/CD, i.e., this is not a requirement to create a Github page.

Thanks for the feedback. As I interpret your comments right I have to push the the whole content of the hugo folder to github and make sure the github pages are configured for the correct path. I.e. public or docs as defined in the config.toml.