如何在Github上托管和预览静态网站?

Abstract:如何把网站托管在GitHub上并能实时预览?本文是Solution ~

利用GitHub Pages托管网站

1.在GitHub上Create a repository

2.Clone the repository to local

1
git clone https://github.com/username/username.github.io

3.Enter the project folder and add an index.html

1
2
cd username.github.io
echo "Hello World" > index.html

4.Push it

1
2
3
4
5
git add --all

git commit -m "Initial commit"

git push -u origin master

或者:

3.创建1个gh-pages分支

1
git checkout -b gh-pages

4.编辑相应的html/css/js文件,放在gh-pages分支上

5.push gh-pages分支到GitHub上

1
2
3
git add <filename>
git commit -m "xxx"
git push -u origin master

预览网站

在项目源代码页面链接前缀那加上http://htmlpreview.github.com/?即可,譬如:

http://htmlpreview.github.io/?https://github.com/ScarlettYellow/presidentMao.github.io/blob/gh-pages/cvsite_1/index.html

Example

自己最近做的毛概作业(给毛爷爷做个简历,于是我就做了个网站…):毛爷爷的个人简历网站

Reference

Github Pages

知乎:怎么预览 GitHub 项目里的网页或 Demo?

Thanks!