Keep gh-pages and master in sync with one line of code

If you publish projects to Github, then you probably are using a gh-pages branch to create a nice home for your project with a demo and some documentation (e.g. like this). Read all about Github Pages at

A common pattern is to keep the gh-pages and master branches in sync with each other — whatever code is in master is the same as your project page (gh-pages). You can read about different ways to do this on Oli Studholme’s excellent article GitHub Pages Workflow and deleting git’s master branch.

I myself favor Lea Verou’s simple approach detailed here. Something along the lines of this:

git add -A .
git commit -m 'Your commit message'
git push origin gh-pages
git checkout master
git rebase gh-pages
git push origin master
git checkout gh-pages

How about we do that in one line? The secret to this will be setting up a Git Alias in our .gitconfig file. I have written about Git Aliases before (see here). If you aren’t already using them to speed up your workflow, then I encourage you to start now. Read about Git Aliases at Git How To

Open up your .gitconfig file (located in your $HOME directory). We will be adding two aliases. The first will be an alias to commit all changes to the current branch (aacm = add all . -git commit –m). Next will be an alias to push the commit to master and then to gh-pages (pomg = push origin master and gh-pages)).

aacm = !git add -A . && git commit -m
pomg = !git push origin gh-pages && git checkout master && git pull origin master && git rebase gh-pages && git push origin master && git checkout gh-pages

Now, when you are on the master branch and you want to sync it to master, simply run:

git pomg

Or, you can combine a commit with the push and sync by running:

git aacm 'Your commit message' && git pomg

Hope that helps your workflows! For more tips on Git Aliases, check out these resources:

Share Your Git Aliases Day

Git aliases have been around for a long time, but in case you don’t know about them, they allow you to create shortcuts for just about any git command or sequence of commands that you can think of. Beyond just the convenience of less key presses, you can use to streamline your workflow by sequencing longer sets of commands that are hard to remember. Here is a nice intro article on Git aliases: Streamline your git workflow with aliases.

Wouldn’t it be fun if today was Share Your Git Aliases Day? Taking a look at other people’s .gitconfig files can give you an insight into how they work and give you ideas for improving your own workflow. For example, check out Must Have Git Aliases: Advanced Examples. Mathias has a really popular .gitconfig in his dotfiles collection that has almost 10K Github stars:

Here’s mine:

Github: From Zero to Hero

Are you looking to get some projects up on Github? There are a few different approaches you can take. Here is mine.

First, you need some projects. Front end projects work best for Github project pages. If you have ideas that involve server-side, you will need to host that aspect of your project somewhere else and you would never want to host any api keys or security-sensitive content on a public Github page (obviously).

For my projects, I like to have my project demo page and the master branch of the code be the same. So, start with your master branch and build it out. There are lots of tutorials on Git and Github, so find one that works for you if you want help getting started.

When your demo is ready, the next step is to create a Github Project Page. This can be accomplished simply by creating a new gh-pages branch that is identical to your master branch.

git checkout -b gh-pages
git push origin gh-pages

As you make changes to the project, keep your gh-pages and master branches in sync. The easiest way to do this is with git rebase.

git commit -m 'my master branch update'
git push origin master
git checkout gh-pages
git rebase master
git push origin gh-pages

For more information on this pattern, read these posts by Lea Verou and Oli Studholme. One thing you could try is to make a project and use it as a git/github playground for experimentation.

So, you have your first project page. Now just rinse and repeat. Once you have a few project pages, you should make them a fancy landing page home for them. For example, I have for my projects. To create one of these, simply create a new repo that follows the naming scheme and build out a nice web page. When you are all set, commit and push to master and you are done.

If you’d like to have your project pages be on a custom non-github domain, Github has a nice help page devoted to that. (Github makes everything so easy – Thanks Github!)

One benefit to having your content on a github domain is superior search rankings. Because of its massive popularity, Github ranks high for authority. This means that if you keep your code projects on Github, and insert links to your other content (blog, twitter, etc.) you will get some nice Google juice out of it.

Not all of your projects will get attention, and that’s ok. Remember, everyone has to start somewhere. Just keep pushing code and improving your skills. Good things are bound to happen. Most importantly: Have fun!