This setup requires two separate repos, one for Hugo's content, and a second one that will be a git submodule with the public folder's content in it.

Step by step:

  1. Create on Github <your-project>-hugo repository (it will host Hugo’s content)

  2. Create on GitHub <username>.github.io repository (it will host the public folder: the static website)

  3. git clone <your-project>-hugo-url && cd <your-project>-hugo

  4. Make your website work locally (hugo server)

  5. Once you are happy with the results, Ctrl+C (kill server) and rm -rf public (don’t worry, it can always be regenerated with hugo)

  6. git submodule add -b master [email protected]:<username>/<username>.github.io.git public

  7. Almost done: add a deploy.sh script to help you (and make it executable: chmod +x deploy.sh):

If submodule already exist you can do this:

$ git submodule init
$ git pull --recurse-submodules

The deploy.sh script:

#!/bin/sh

echo "\033[0;32mDeploying updates to GitHub...\033[0m"

# Build the project.
hugo # if using a theme, replace by `hugo -t <yourtheme>`

# Go To Public folder
cd public
# Add changes to git.
git add -A

# Commit changes.
msg="rebuilding site `date`"
if [ $# -eq 1 ]
  then msg="$1"
fi
git commit -m "$msg"

# Push source and build repos.
git push origin master

# Come Back
cd ..

Run ./deploy.sh "Your optional commit message" to send changes to <username>.github.io (careful, you may also want to commit changes on the <your-project>-hugo repo).

Source: https://gohugo.io/tutorials/github-pages-blog/