Skip to content

Instantly share code, notes, and snippets.

@JamesSkemp
Last active March 5, 2016 04:45
Show Gist options
  • Save JamesSkemp/d09f6a6ebfe670986e26 to your computer and use it in GitHub Desktop.
Save JamesSkemp/d09f6a6ebfe670986e26 to your computer and use it in GitHub Desktop.
1. Create Git repo: https://github.com/JamesSkemp/blog.git
2. Clone locally:
	C:\Users\James\Projects> git clone https://github.com/JamesSkemp/blog.git
3. .\hugo.exe new site blog --force
4. cd blog
5a. Create content\posts\ and put file within
5b. Could also run ..\hugo.exe new posts\test.md and then either switch from draft or have Hugo check drafts
6. ..\hugo.exe server
7. Test site (doesn't work / blank)
8. mkdir themes
9. add theme to above directory (used beg)
10. Add new line to config.toml
	theme = "beg"
11. Refresh page in browser. Should display data now.
12. Update config to add
	publishdir = "public"
13. Run ..\hugo.exe to generate public folder contents, and should look right

14. Stop hugo server from above
15. Run some commands from https://gohugo.io/tutorials/github-pages-blog/
	all run from projects\blog








# Create a new orphand branch (no commit history) named gh-pages
git checkout --orphan gh-pages

# Unstage all files
git rm --cached $(git ls-files)

# Grab one file from the master branch so we can make a commit
git checkout master README.md

# Add and commit that file
git add .
	didn't have to do that
git commit -m "INIT: initial commit on gh-pages branch"

# Push to remote gh-pages branch
git push origin gh-pages

	had to clean out the directory manually first. might have been because I was still running hugo server

# Return to master branch
git checkout master

# Remove the public folder to make room for the gh-pages subtree
rm -rf public

	didn't have a public folder

# Add the gh-pages branch of the repository. It will look like a folder named public
git subtree add --prefix=public git@github.com:spencerlyon2/hugo_gh_blog.git gh-pages --squash

	C:\Users\James\Projects\blog [master]> git subtree add --prefix public https://github.com/JamesSkemp/blog.git gh-pages --squash

# Pull down the file we just committed. This helps avoid merge conflicts
git subtree pull --prefix=public git@github.com:spencerlyon2/hugo_gh_blog.git gh-pages
	
	git subtree pull --prefix public https://github.com/JamesSkemp/blog.git gh-pages

# Run hugo. Generated site will be placed in public directory (or omit -t ThemeName if you're not using a theme)
hugo -t ThemeName


# Add everything
git add -A

# Commit and push to master
git commit -m "Updating site"
git push origin master

# Push the public subtree to the gh-pages branch
git subtree push --prefix=public git@github.com:spencerlyon2/hugo_gh_blog.git gh-pages
	git subtree push --prefix public https://github.com/JamesSkemp/blog.git gh-pages






	FYI: hugo --buildDrafts


Now, as you add new posts to your blog, you will follow steps that look something like the following:

Create the Markdown source for the new post within the content/posts directory
Preview your work by running Hugo in server mode with hugo server
Run Hugo not in server mode so that the generated urls will be correct for the website
Add and commit the new post in master branch
Push the master branch
Push the public subtree to the remote gh-pages branch
@JamesSkemp
Copy link
Author

Another usage of part of this is to create a repo that just hosts a site. See https://github.com/JamesSkemp/gits-matrix for an example, including git commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment