Gitpages + Hugo website deployment

Hi,

I’ve built a site using Hugo and am now attempting to deploy it using GitHub pages, and I must’ve deleted and retried this over ten times now - I’m specifically having trouble with step 5 of the provided instructions (https://gohugo.io/hosting-and-deployment/hosting-on-github/) which entails linking a public folder with the repo I’m hosting my site from.

My main repo: https://github.com/NickWerren/QC_container/

Everything works locally, it’s just deployment where I’m having the issue. I am having numerous issues but the current one is that I’m trying to run

git submodule add -b master public

I get the error message that a git directory already exists locally. After clearing that out from the .git file, and then running the above command again then I get the error that “I appear to have cloned an empty repository […] unable to checkout submodule ‘public’”

I have no idea where I am going wrong or how to make this work. Thanks for any help in advance!

1 Like

the current one is that I’m trying to run

 git submodule add -b master public

[…] then I get the error that “I appear to have cloned an empty repository […] unable to checkout submodule ‘public’”

When adding a submodule you should provide the URL of the repository you want to include as a submodule, whereas in the above command you only provided what appears to be a folder name (public) — which is consistent with the error reporting the impossibility to checkout the public repository.

This is also confirmed in the Hugo tutorial step you linked, which provides the syntax template for the Git submodule command:

git submodule add -b master https://github.com/<USERNAME>/<USERNAME>.github.io.git public

So, basically, you need to substitute in the above command all occurrences of <USERNAME> with NickWerren:

git submodule add -b master https://github.com/NickWerren/NickWerren.github.io.git public

which will point your public folder (the Git submodule) to your GitHub Pages User website repository:

Basically, the above steps allow you to ensure that your local Hugo website will build the static website into the public/ folder, which is also your local clone of your GH Pages repository. The need for using a Git submodule is only to allow you to version control via Git your Hugo project sources — a submodule being just a repository nested into another repository, where the latter can decide which commit to checkout from the former. In your case, you’ll be using the submodule to build and publish/update the GH Pages contents.

References

Also, if you don’t like working with Git submodules, you can consider using git-subrepo instead, a tool by Ingy döt Net and Magnus Carlsson:

1 Like