Posted by Blog - uTIcARdI on January 27, 2019

Hugo provides the detail instructions about how to deploy it on different environment.

At first, I followed Deployment of Project Pages from /docs folder on master branch, and put all files in one repository.

I continue to check Deployment of Project Pages From Your gh-pages branch after I did some customization on hugo-theme-cleanwhite and want to publish the change to the forked branch.

Instead of follow Hugo guide, I did some try myself. I searched “change a subfolder to another repository and found the article: Moving Files from one Git Repository to Another, Preserving History but its case is:

  • Move directory 1 from Git repository A to Git repository B
  • repository A as a branch in repository B

Searched and read following links:

Create Repositories on GitHub


Refer to Quick start: Setting up a custom domain

  1. Custom Domain

    For my case, I configured “” as Custom domain in

  2. DNS system

    Created a CNAME record: to on the DNS system.

    Compared the free version of cloudflare, Namecheap, and, I would say is a better choice as a DNS Hosting Provider.

Push local files to new Repositories

  • Disable publishDir option in config.toml
  • Update baseurl in config.toml The value can be kept, but for my case, I migrated my blog from “” to “”.
  • run hugo to generate published files.
  • Check public folder and make sure the files were generated
  • Push files

    • In the root folder of the Hugo project, run following commands to push local files to

      mkdir pubic
      git clone --no-checkout  temp
      mv temp/.git public
      rm -r -f temp
      cd public
      git add .
      git commit -m "Initial commit"
    • Login to github and confirmed that all files were pushed.

      Verified as well, it works.

    • Do the same thing on folder theme/hugo-theme-cleanwhite with the url:

Git Submodules

In the root folder of Hugo project, run the command:

git rm -r public
git submodule add public/
git add .
git commit -m "add submodule"
git push --force

Do the same thing on folder theme/hugo-theme-cleanwhite with the url:

For git rm, the data can be removed from history by following: Removing sensitive data from a repository

Deployment script

Update hugo deployment script for all repositories:


#remove old files
rm -r -f ./public/*
find . -name '.DS_Store' -type f -delete

# Build the project, if using a theme, replace with `hugo -t <YOURTHEME>
./hugo_0.53_osx/hugo -t hugo-theme-cleanwhite --quiet --cleanDestinationDir --minify --gc

#add CNAME back
echo "" >> ./public/CNAME

#add License

if [ "$1" != "testing" ]
    echo -e "\033[0;32mDeploying updates to Algolia...\033[0m"
    npm run algolia

    # git push --recurse-submodules=on-demand

    echo -e "\033[0;32mpush changes on submoudle: theme...\033[0m"
    cd themes/hugo-theme-cleanwhite
    git add .
    git commit -m "$1"
    git push

    echo -e "\033[0;32mpush changes on submoudle: public...\033[0m"
    cd ../../public
    git add .
    git commit -m "$1"
    git push

    echo -e "\033[0;32mAdd changes to current repo....\033[0m"
    cd ..
    git add .
    git commit -m "$1"
    git push

Clean up

Since I moved my blog from ‘’ to ‘’, I redirected the traffic to new domain by following Redirects on GitHub Pages.

Removed all files in folder: docs (Keep CNAME file there), and new files: _config.yml and index.html

  • The content of _config.yml

    - jekyll-redirect-from 

  • The content of index.html

    title: Kexian Zhang's Blog
    - /sitemap.xml
    - /index.xml
    - /2019/01/23/try-aiohttp/
    - /2019/01/19/get-in-dict-get/
    - /top/about/
    - /2019/01/01/hello-world/
    - /2018/12/27/aws-s3-bucket-creation/
    - /2018/12/26/jenkins-xcode-plugin-parameterized-project/
    - /2018/12/27/python-trick-double-stars/
    - /2018/02/09/run-asa9.1-on-eve/
    - /2018/12/19/ipsec-over-paloalto-fw-static-nat/
    - /2018/12/18/jenkinsx-iosproject-delivery/
    - /2018/12/17/wireshark-vnc-integrate-eve-ngunlonosx/
    - /2018/10/11/ansible-access-network-netconf/
    - /2018/10/07/netconf-feature-on-cisco-ios-iosxe/
    - /2018/09/21/monitor-network-connections-based-on-process/
    - /2018/09/07/ansible-access-network-via-ssh/
    - /2018/09/04/ansible-access-network-via-telnet/
    - /2018/07/20/mininet-importerror-customclass/
    - /2018/04/16/flask-flask-wtf-flask-bootstrap-select2-jinja2-i
    - /2018/02/13/python-smtplib-email/
    - /2018/01/25/run-paloalto-vm-on-eve-unl-virtualbox-osx/
    - /2017/09/22/tc-how-it-works-on-different-ips/
    - /2017/06/06/overflowerror-signed-char-is-greater-than-maximu
    - /2017/03/24/cisco-ipsinline-vlan-pair-mode/
    - /2017/01/08/run-nx-osv-9000-on-eve-unl/
    - /2016/11/29/adding-realtek-8139-driver-to-esxi6/
    - /2016/11/30/run-ansible-on-windows/
    - /2016/07/21/loop-a-dict-to-update-key/
    - /2016/01/08/vsphere6-vcenter6-installation/
    - /2013/12/20/dynagen-dynamips-error-netio_desc-create-udp-una
    - /2016/01/28/snmp-simulator-installation-guide/
    - /2013/11/13/trouble-shooting-cisco-router-dhcp-no-option125/
    - /2013/11/05/make-error-usrbinld-cannot-find-luuid/
    - /search/placeholder/
    - ""



Scan the QR code using WeChat

comments powered by Disqus