Creating GitHub pages from the command line

If you're familiar with command-line Git, it's straightforward to manually create a Github Pages site.

Make a fresh clone

To set up a Project Github Pages site, you need to create a new "orphan" branch (a branch that has no common history with an existing branch) in your repository. The safest way to do this is to start with a fresh clone:

$ git clone
# Clone our repository
Cloning into 'repository'...
remote: Counting objects: 2791, done.
remote: Compressing objects: 100% (1225/1225), done.
remote: Total 2791 (delta 1722), reused 2513 (delta 1493)
Receiving objects: 100% (2791/2791), 3.77 MiB | 969 KiB/s, done.
Resolving deltas: 100% (1722/1722), done.

Create a gh-pages branch


Switch directories into your new cloned repository:

$ cd repository


Check if your repository already has a gh-pages branch:

$ git branch
# shows a list of branches for your repository
* branch-name
* branch-name


If you don't already have a gh-pages branch in your repository, create a new gh-pages branch:

$ git checkout --orphan gh-pages
# Creates a `gh-pages` branch, without any parents (it's an orphan!)
Switched to a new branch 'gh-pages'

Remove all files to create an empty working directory

$ git rm -rf .
# Remove all files from the old working tree
rm '.gitignore'

Add content and push

$ echo "My Page" > index.html
$ git add index.html
$ git commit -a -m "First pages commit"
$ git push origin gh-pages

Load your new GitHub Pages site

After your push to the gh-pages branch, your Project Pages site will be available at 'http(s)://[username][projectname]' . Note that Pages are always publicly accessible when published, even if their repository is private.

comments powered by Disqus