Skip to content

Instantly share code, notes, and snippets.

@codenameyau
Last active January 1, 2018 05:02
Show Gist options
  • Save codenameyau/7dada286f0ca8b464c90 to your computer and use it in GitHub Desktop.
Save codenameyau/7dada286f0ca8b464c90 to your computer and use it in GitHub Desktop.
Deploying to GitHub Pages

Deploying to GitHub Pages

You can serve your project websites for free on GitHub Pages. Normally, I use gulp to generate a minified and concatenated build inside the build/ directory, and then use git subtree to push only the build/ directory to the gh-pages branch (without needing to push the build to master).

First Push to GitHub Page

git subtree push --prefix build origin gh-pages

Updating Your GitHub Page

The easiest thing to do is to delete the existing gh-pages branch and run the command above again. You can also checkout that branch and pull from master.

Otherwise you can follow these step.

# First remove build from .gitignore
git commit -m "Deploying to gh-pages"
git branch -D gh-pages
git subtree split --prefix build -b gh-pages
git push -f origin gh-pages:gh-pages

# Lastly undo changes to master branch
git reset --hard HEAD~1

Troubleshooting

When things don't work out as planned, I recommend deleting the existing gh-pages branch on GitHub, then reclone the repository and re-run the following command.

git subtree push --prefix build origin gh-pages
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment