Next, set up version control and publishing from a gh-pages branch.
In the terminal, from the example-site folder, create a git repo, configure the .gitignore file, commit the changes locally, and push everything to GitHub:
git init
echo "/public" >> .gitignore
git add .
git commit -m "initial commit"On github.com, click the ‘Start a project’ button.
Use example-site for the Repository name and click the ‘Create’ button.
In your terminal, add the newly created GitHub repo as your remote origin. You can use ssh or HTTPS to authenticate with GitHub:
Important: Substitute your own GitHub username in place of <github-username>:
Using ssh authentication:
git remote add origin git@github.com:<github-username>/example-site.gitUsing HTTPS authentication:
git remote add origin https://github.com/<github-username>/example-site.gitNote: You may need to consult GitHub’s authentication documentation if it has not already been configured.
Push your local branch up to GitHub.com. Setting the -u flag will designate it as your upstream repo moving forward:
git push -u origin mastergh-pages branchOpen the config.tomlfile in a text editor and update first line to:
baseURL = "https://<github-username>.github.io/example-site"Commit the change and push it up to GitHub:
git commit -am "Updating the baseURL."
git push origin masterCreate an empty gh-pages branch and push it up to GitHub:
git checkout --orphan gh-pages
git rm -rf .
git commit --allow-empty -m "Init empty branch"
git push origin gh-pages
git checkout masterCreate a worktree for the gh-pages branch in a folder called public:
git worktree add -B gh-pages public origin/gh-pagesBuild your Hugo site locally from the root project folder:
hugo
Change directory into your public folder, then add and commit the generated html to the gh-pages branch:
cd public
git add .
git commit -m "Publishing to GitHub pages."Push the gh-pages branch up to GitHub and wait for a few minutes for your website to build.
git push origin gh-pagesYour site should now be live at https://<github-username>.github.io/example-site.
Note: You can repeat these last three steps to manually publish the locally generated website to your gh-pages site at anytime.
Now you are ready to automate the publishing process using Wercker: Automating the publishing process with Wercker