Sometimes you want to have a subdirectory on the master branch be the root directory of a repository’s gh-pages branch. Here's how to do it:
For the sake of this example, let’s pretend the subfolder containing your site is named dist.
Remove the dist directory from the project’s .gitignore (or skip and force-add afterwards).
Make sure git knows about your subtree (the subfolder with your site).
git add distor force-add it if you don't want to change your .gitignore
git add dist -fRemember to commit!
git commit -m "gh-pages first commit!"Use subtree push to send it to the gh-pages branch on GitHub.
git subtree push --prefix dist origin gh-pagesBoom. If your folder isn’t called dist, then you’ll need to change that in each of the commands above.
If you do this on a regular basis, you could also create a script containing the following somewhere in your path:
#!/bin/sh
if [ -z "$1" ]
then
echo "Which folder do you want to deploy to GitHub Pages?"
exit 1
fi
git subtree push --prefix $1 origin gh-pagesWhich lets you type commands like:
git gh-deploy path/to/your/site
After running
git subtree push --prefix build origin gh-pages(my directory was called build, not dist) I was never able to update my Github Pages code. I could merge my changes from master into my gh-pages branch, and push the changes to my gh-pages branch up. But the content of the Github Pages page never changed. Ultimately I had to delete the gh-pages branch and re-push using the command you mentioned. Can you explain why updating the gh-pages branch doesn't result in changes to the visible (frontend) Github Page?