I have several projects which have Github Pages content on a gh-pages branch. While the simple approach of checking out gh-pages when I want to change the content does work, it has some annoying side effects.
- I can’t see the code and the website at the same time
- Visual Studio really doesn’t like it when the project file suddenly disappears.
Cloning the repository into a separate folder for editing pages works better, but produces annoying warning messages when pushing and requires unnecessarily downloading the content twice.
The git commands below allow you to connect to a single branch so that the gh-pages branch is effectively in its own repository.
Create a local repository for pages
git init appname-pages cd appname-pages
Add the remote. The additional settings tell git to ignore everything except gh-pages
git remote add -t gh-pages -m gh-pages origin email@example.com:username/appname.git
If gh-pages does not exist, rename the empty master branch created by init and push to the remote after adding some content.
git add . git commit -m "initial commit" git branch -m master gh-pages git push origin gh-pages
If gh-pages already exists on the remote, check it out and remove the empty master branch.
git pull git checkout gh-pages git branch rm master
If gh-pages exists in your main local repo (you edited it there or it existed before cloning), you may need to remove it.
git branch rm gh-pages