[SOLVED] Git question: Move changes on master branch to github pages

[SOLVED] Git question: Move changes on master branch to github pages


I have started learning git and github on my own. I am not at the Git stage at FCC but decided to go ahead anyway with online tutorials elsewhere. I find the basic idea of git quite straightforward. Once I am “fluent” I expect git will be second nature. Saving endless copies of a project with a homemade naming convention is a thing of the past I hope.

I am learning git as I move my copepen projects to github pages. I exported the codepens to my own machine, made some changes, initialised git and pushed to github. If you look at my pizza_site repo you’ll see two branches. master and gh-pages. The latest commit was on the gh-pages branch. Now I would like to sync that change to gh-pages change back to master. But I also want to keep the gh-pages branch.

When I look at command such as git find push or merge I always have the feeling that I could be making changes in the wrong direction.

I found this link where Mandi Wise is discussing a similar solution. But if I understand her correctly she uses use git-rebase to push changes from master to gh-pages. I want to do the opposite; from gh-pages to master.

Any ideas?


Actually, you should be doing all your work in the master branch. Then when you are ready to go live with your changes, merge them into the gh-pages.

You can think of it this way for gh-pages.

  • master branch = development
  • gh-pages branch = production


Hi @jamesperrin and thanks for your reply. Most of the tutorials I have seen describe the how of git but not the why. They way you describe the branches and their purposes makes sense and really goes to the root of my confusion.

I think about the branches in this way.
gh-pages = development
master = backup.

The reason is this: I loaded jQuery with http This worked fine on master when I opened the page locally in a browser. But once I published on github pages jQuery would not load until I changed to HTTPS. I would not have discovered this flaw on master anyway.


You have to remember master being the development branch only applies to gh-pages. Normally, the master branch in your production code. While developing, you create a branch like for a new feature. When finished coding, you will merge your new feature branch into your master branch. Then, you would push the new code to your production server.


Note that this was my very first attempt at publishing on gh-pages (in fact publishing anything online save for codepen ) and it has of course colored my experience. In my example about loading jQuery it was an error I could only detect once I published on gh-pages. I can imagine there are similar examples of flaws and and quirks that only become apparent once a webpage is actually published. Is that the wrong conclusion I’ve arrived at?

The workflow you suggest mean I need to trust master and testing a page on my local machine to reliably indicate what the output on gh-pages will look like. I have another codepen that I will export to my local machine. and this time I will use the branches in the way you suggest; master for development and gh-pages for production and see how that works.


You can use the following links for better understanding for git branching and merging.

Branches aren’t just for birds (jlord.us)
Merging vs. Rebasing (atlassian.com)
Advanced Git Tutorials (atlassian.com)


It worked. Thanks @jamesperrin

I used the master branch for development as you suggested. Once I was happy with master I moved the changes to gh-pages with these commands.

git checkout gh-pages
git merge master
git push origin gh-pages
git checkout master 

I decided to stay away from the git rebase command at there seem to be a lot of situation where it should be avoided. Merge is a easier concept for me to grasp as a beginner.

I have renamed the topic to be more specific and marked it as solved.


For anyone who is reading this thread and also is thinking of moving their portfolio to github I will list the resources that I used in logical progression below. Installation is very machine specific but there are many resources out there you’l find with a simple google search. I’ve used the terminal istead of any GUI and so farI like that way of working with git. I am using Bash on Ubuntu on Windows.as my terminal for example.

Mario Kaack explains on his YouTube channel how to work with git on a local machine.

And then how to push to github

Next how to create a gh-pages branch and publish to github pages.

And finally merging changes from master to gh-pages, again the commands I listed earlier.

git checkout gh-pages
git merge master
git push origin gh-pages
git checkout master 

I hope this thread can be helpful for anyone curious about starting with git.