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 github.com/user/repository.git
# 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

1

Switch directories into your new cloned repository:

$ cd repository

2

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

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

3

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].github.io/[projectname]' . Note that Pages are always publicly accessible when published, even if their repository is private.


https://help.github.com/articles/creating-project-pages-from-the-command-line/

comments powered by Disqus