Angelos Chalaris Angelos Chalaris - 1 year ago 118
Git Question

Bring gh-pages up to date with the latest commit of master

I am using SourceTree in combination with a Github repository for version control for a project. For a while, I've been using

to commit all new changes, but every now and then, I want the
branch to fast-forward to the latest commit of
, so that I can update the live page with the page I have in production (usually when a major update is finished).

I have tried rebasing, as another SO post suggested, but this made the problem even worse, as SourceTree had me manually choose what changes I wanted and the rebasing took a little while especially considering the amount of commits between the last update of
. After successfully rebasing in one project, I could basically sync the
branch to
whenever I desired and all in-between versions would commit automatically (I could not reproduce the same behavior in another repository though). However, what I want is to get the last commit and overwrite all files. To do this, I usually just copy the whole folder while on
branch to another location, then switch to
and overwrite all files manually. This is sub-optimal, though and can get really problematic for larger projects.

So, what I want and need is to automate this procedure, either through SourceTree or via a script.

TL;DR: I need a way to update
to the latest
commit semi-automatically, which will overwrite all files with the ones in
without rebasing and will then push them to the Github repository.

Answer Source

However, what I want is to get the last commit and overwrite all files.

You should:

  • merge gh-pages to master with the --ours option (so master is actually untouched).
  • merge master to gh-pages (which means gh-pages fast-forwards to master and becomes identical)


git checkout master
git merge --ours gh-pages
git checkout gh-pages
git merge master

Don't forget though that since a few days ago, you don't have to maintain a gh-pages branch anymore.

Simpler GitHub Pages publishing now allows to keep your page files in a subfolder of the same branch (no more gh-pages needed):

Now you can select a source in your repository settings and GitHub Pages will look for your content there.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download