How to clone a specific branch from a git repo

When I was developing this blog using Pelican, I faced a problem with git. As this blog is hosted by github pages and they serve the pages as static html file from master branch. Now, I also wanted to version the core code related to html page generation, for example, the theme and config files. I could not put them in the same git repo as Pelican generates static files in a directory inside the root blog directory called output. According to github pages requirement, that has to be in the master branch.

So, I found a solution on statckoverflow. The solution was to commit the code in two separate branches. I added all the core codes including content, themes, config files in a git branch called core_code and I added all the static generated html, js, css files into master branch of the same git repository.

First, I added a .gitignore and added output to it to make sure that when I added the all core Pelican code into core_code branch, the generated static files in output does not get added too.

Then I added and committed the code in root blog directory in the core_code branch.

$ git push origin core_code

Then go to the output directory, and commit it in the master branch:

$ git push origin master

When I clone the repo an another system, I just clone the core_code branch first:

$ git clone -b core_code

Then, go to the created git repo directory:

$ cd
$ mkdir output
$ cd output
$ git clone -b master .

That is how I maintain my blog code in a single repo and I can check them out in the same setup so that I can start using the code in any new system without much problem except of those related to installing Pelican.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Back To Top