[Makefile] Publish to GitHub Pages Automatically

Assume we have the following repo:


We want to automate the publish of static website to GitHub Pages.

Here is what I do:

First create a gh-pages branch:

# clone repo
$ git clone https://github.com/myname/myrepo.git
$ cd myrepo
# create *gh-pages* branch
$ git checkout -b gh-pages
# push *gh-pages* on GitHub
$ git push origin gh-pages

Then use the following code to push static contents to GitHub Pages:


      @echo "\033[92mClone $(REPO) ...\033[0m"
      rm -rf $(REPO_DIR)
      git clone https://$(REPO).git $(REPO_DIR) --depth=1
      @echo "\033[92mGit checkout gh-pages ...\033[0m"
      cd $(REPO_DIR); git checkout gh-pages; rm -rf *
      # Build you contents here
      @echo "\033[92mPush to Remote Repo ...\033[0m"
      cd $(REPO_DIR); git add .; git commit -m "update site"; git push

Tested on Ubuntu Linux 16.10, GNU make 4.1-9.


[3]Create a new branch with git and manage branches · Kunena/Kunena-Forum Wiki · GitHub