31 Jan 2012

Make a GitHub Project Page that's an exact mirror of your Master branch


GitHub has a Project Pages feature that creates a webpage based on the content of the gh-pages branch of a repository. I asked, and subsequently answered, the question of how to get the Project Page to be an exact mirror of the Master branch over on Stack Overflow.

One way I found is to run the following command, which sets a configuration setting that causes every subsequent instance of git push to push the Master branch of the repository into the gh-pages branch: git config --add remote.origin.push +refs/heads/master:refs/heads/gh-pages

The trouble with this solution is that I'm using the GitHub Mac App, which doesn't use a strict git push. According to their Help page, it does a git pull --rebase. Additionally, even when I select Push from the Repository menu, my git config line isn't adhered to. I'm not sure what's up with that...

I ran through a bunch of my own tests, trying to figure out how this branch mirroring can be done in a GitHub-For-Mac-App-Friendly way. It doesn't seem like you need to go through the exact process they've described to create the gh-pages branch. Over there, they provide the following process along with the disclaimer "Caution: make your working directory clean before you do this (either stash or commit), otherwise this will lose any changes you've made to your project since the last commit.":

cd /path/to/repo-name
git symbolic-ref HEAD refs/heads/gh-pages
rm .git/index
git clean -fdx
echo "My GitHub Page" > index.html
git add .
git commit -a -m "First pages commit"
git push origin gh-pages

Instead, you can simply create a new branch named gh-pages from within the GitHub Mac App. They probably don't instruct people to do this because what I'm accomplishing here isn't a typical scenario.

You can take these steps to create the 'gh-pages' branch from within the GitHub Mac App:

  1. Go to the Branches view of your repository
  2. Click the + button on your Master branch to create a new branch - name this 'gh-pages'
  3. Click the Publish button to push it to GitHub
  4. Use the bottom left menu to checkout the Master branch, if you're not working in the Master branch

Each time you want to update your Project Page, just run these steps to sync your Master branch into your gh-pages branch within the GitHub Mac App:

  1. Switch to Branches view
  2. Click the Merge View button to display the Merge view
  3. Drag the Master branch to the left slot & the gh-pages branch to the right slot
  4. Click the Merge Branches button
  5. Use the bottom left menu to checkout the gh-pages branch
  6. Click the Branch in Sync button to force a synchronization

Tags

development git github mac stack-overflow

Related Posts

17 Dec 2013 Donoku
28 Dec 2012 How to make SublimeLinter work with Ruby & RVM
09 Dec 2012 The tech behind getting Blizzalert into its third season
03 Nov 2012 Little-Corner is now a Heroku-ready Rails app
14 Oct 2012 Sip as a replacement for Pick as a replacement for Digital Color Meter in Mac OS X