It's our wits that make us men.

Git创建github博客详细攻略

Posted on By lk

说明: 首先,你需要注册一个 github 账号,最好取一个有意义的名字,比如姓名全拼,昵称全拼,如果被占用,可以加上有意义的数字.
本文中假设用户名为 tiemaocsdn

1. 注册账号:

地址: <a target=_blank target=”_blank” href=”https://github.com/”>https://github.com/</a>
输入账号、邮箱、密码,然后点击注册按钮.
<div style="text-align: center;"></div><div style="text-align: center;">图1 第1步</div>2. 初始设置
注册完成后,选择Free免费账号完成设置。
<div style="text-align: center;"></div><div style="text-align: center;">图2 第2步</div>2.1 验证邮箱
请打开你的邮箱,查看发送给你的确认邮件,你需要验证邮箱后,后面生成的个人主页才会被接受和发布.

3. 创建页面仓库
地址: <a target=_blank target=”_blank” href=”https://github.com/new”>https://github.com/new</a>
这个仓库的名字需要和你的账号对应, 如 tiemaocsdn.github.io
输入基本信息,然后点击创建仓库.
<div style="text-align: center;"></div><div style="text-align: center;">图3 第3步</div>4. 进入项目设置页面
因为这个项目就是专门的放页面的,所以master分支即可. 如果是你的某个仓库的页面,你需要设置到 gh-pages 分支中,关于这些,请参考本文末尾提到的参考资料.
<div style="text-align: center;"></div><div style="text-align: center;">图4 第4步</div>
5. 进入自动页面生成器
在设置页面,下拉到底部, 默认分支(master)不用管.
<div style="text-align: center;"></div><div style="text-align: center;">图5 第5步</div>
6.1 创建用户页面(即技术博客站点)
输入一些内容,可以自己编辑,也可以从readme加载:
<div style="text-align: center;"></div><div style="text-align: center;">图6-1 第6-1步</div>
6.2 继续,选择主题
<div style="text-align: center;"></div><div style="text-align: center;">图6-2 第6-2步</div>
7. 选择主题,然后发布
如下图所示,其实这些以后你都可以自己修改替换,这只是生成一些css,html,img到你的仓库里面.
<div style="text-align: center;"></div><div style="text-align: center;">图7 第7步</div>
8. 查看效果
现在,你可以访问自己的GitHub.io 上的主页了,例如:
<a target=_blank target=”_blank” href=”http://tiemaocsdn.github.io/”>http://tiemaocsdn.github.io/</a>
页面效果如下图所示:
<div style="text-align: center;"></div><div style="text-align: center;">图8 第8步</div><p>
</p><p>9. CNAME绑定域名
</p><p>到这一步,其实已经很明确了, <a target=_blank target=”_blank” href=”http://tiemaocsdn.github.io/”>http://tiemaocsdn.github.io/</a> 这么一个域名,就指向了刚刚构建的这个站点/页面。 如果嫌弃这个域名太土了怎么办? </p><p>其实很好办,花钱买个喜欢的域名映射过去就好了。 在根路径下创建一个文件, 文件名是大写的 "CNAME", 注意没有后缀。 因为tiemaocsdn 没有购买域名,那么就拿另一个来说事吧。</p><p>类似下面这样:</p><p><a target=_blank target=”_blank” href=”https://github.com/renfufei/renfufei.github.io/blob/master/CNAME”>https://github.com/renfufei/renfufei.github.io/blob/master/CNAME</a>
</p><p>里面的内容,就是访问此 xxx.github.io 时会重定向到此域名,所以其实这个地址可以是任意值。 但是为了有意义,我们可以定义为某个固定的域名,例如 :</p><p></p><pre code_snippet_id="517110" snippet_file_name="blog_20150401_1_8936909" code_snippet_id="517110" snippet_file_name="blog_20150401_1_8936909" name="code" class="plain">blog.cncounter.com</pre>文件的内容只有一行,这样访问 <a target=_blank target=”_blank” href=”http://renfufei.github.io”>http://renfufei.github.io</a> 时浏览器就接收到重定向指令,跳转到CNAME里面指定的域名去了。  <p></p><p>大致的响应头和状态码如下,你也可以使用Chrome打开NetWork,勾选上 Preserve Log 保留日志看一看相关信息:</p><p></p><pre code_snippet_id="517110" snippet_file_name="blog_20150401_2_4080570" code_snippet_id="517110" snippet_file_name="blog_20150401_2_4080570" name="code" class="plain">Request URL:http://renfufei.github.io/ Request Method:GET Status Code:301 Moved Permanently

Location:http://blog.cncounter.com/ Server:GitHub.com</pre>这样就很明白了,访问此站点时,如果域名不是 blog.cncounter.com ,那么就会跳转到 http://blog.cncounter.com/,个人恶意推测,即便你将CNAME文件的内容设置为 www.baidu.com 也是可行的,这样访问的时候直接跳转到百度了。
但是,如果 <a target=_blank target=”_blank” href=”http://blog.cncounter.com/”>http://blog.cncounter.com/</a> 是空的怎么办?  这就需要你自己保证咯。<p></p><p>当然,要是这么结束掉,那本文就是一篇坑文。 
如果你持有这个域名,那么你可以将域名的对应记录也CNAME到 "renfufei.github.io" . 记住, renfufei.github.io 已经是一个互联网上能明确定位到的地址,所以DNS记录完全可以映射到此路径.</p><p>例如如下的记录, DNS中,A记录那就是直接指定一个IP。 CNAME就是重命名,指向另一个域名。 主机记录就是前缀,例如: blog, 与 cncounter.com 拼接在一起就是 blog.cncounter.com ,如果你想映射 www.cncounter.com ,那么主机记录就是 www ,记录类型是CNAME,记录值是renfufei.github.io;如果想将 http://cncounter.com 这个根域名也映射到,那么记录类型也是CNAME,主机记录就是一个英文的 at: "@". 你可以将多个域名都映射到 xxxxx.github.io 之类的你自己的站点上,但原则上都会跳转到你新建的 CNAME文件中的域名上。【放心,不会死循环。。。】.好的,恭喜你!</p><p>
</p><p style="text-align: center;">
</p><p>10. 仓库的页面</p><p>创建好个人或组织的Github首页之后,就拥有了一个固定的二级域名。 </p><p>那么,每个项目都可以使用页面生成器生成一个项目的页面(page)。 当然,项目使用的 pages 就不是 master 分支了,而是一个叫做 gh-pages 的分支。gh 是 github 的简称, github会自动解析下面的页面。</p><p>相应的访问路径类似 http: //xxx.github.io/project-name/ 这样。例如: <a target=_blank target=”_blank” href=”http://blog.cncounter.com/cncounter/”>http://blog.cncounter.com/cncounter/</a></p><p>对应的分支为: <a target=_blank target=”_blank” href=”https://github.com/cncounter/cncounter/tree/gh-pages”>https://github.com/cncounter/cncounter/tree/gh-pages</a></p><p>有兴趣你可以点进去看看,生成方式和上面的基本一样。 当然,Github现在改版了,新版的布局,Settings 被挪到了上方,但是基本操作还是不变的。</p><p style="text-align: center;">cnc-github
</p><p>
</p>注意事项:
<ul><li>如果报404,或者其他错误,请稍等,或者检查你的邮箱,看看构建失败的提示信息.</li><li>比如我的,因为最初没有验证邮箱,结果收到了好几次发布失败的通知(如下面的邮件提示)。</li><li>以后每次你提交(或在线修改后提交)文件到这个仓库,GitHub 都会自动为你构建,并发布。</li><li>所以,有问题,请修改并提交某个文件,重新试试吧!</li></ul><pre code_snippet_id="517110" snippet_file_name="blog_20141112_1_3528502" code_snippet_id="517110" snippet_file_name="blog_20141112_1_3528502" name="code" class="plain">The page build failed with the following error:

You need a verified email address in your GitHub account to publish Pages. You can verify your email addresses from your Settings panel:

https://github.com/settings/emails

If you have any questions please contact us at https://github.com/contact.</pre>
下面是参考的一部分:

您可以通过GitHub的页面自动生成器快速为 项目,用户(User,比如你的账号),或组织(Organization, 比如 alibaba) 创建一个网站(其实就是技术博客啦)。

生成用户/组织的网页

要生成用户/组织的网站页面,你需要创建一个仓库(repository,代码库),名为: username.github.io 或 orgname.github.io ; 用户名或组织名 必须 是你自己的账号/或所属的组织, 否则GitHub Pages 站点不会帮你生成(build,构建,编译,)。 GitHub的页面自动生成器可以通过仓库的设置页面(Settings page)看到。 您可以阅读更多<a target=_blank target=”_blank” href=”https://help.github.com/articles/user-organization-and-project-pages”>关于用户和组织页面的内容</a> 。

警告: GitHub页面网站在互联网上是公开,即使其所属的仓库是私有的。 如果你有敏感数据在页面仓库中,您可能需要在发布之前删除他们。

参考地址:
<ul><li><a target=_blank target=”_blank” href=”https://help.github.com/categories/20/articles”>Categories / GitHub Pages Basics</a></li><li><a target=_blank target=”_blank” href=”https://help.github.com/articles/user-organization-and-project-pages”>User, Organization, and Project Pages</a></li><li><a target=_blank target=”_blank” href=”https://help.github.com/articles/creating-pages-with-the-automatic-generator”>Creating Pages with the automatic generator</a></li></ul>如果你看到这里,如果你已登录, 如果觉得对你有帮助,请点击下面的 “顶” 按钮.
<p>如果有问题,有建议,请留言。</p><p>赶快试试吧!</p>GitHub.io技术博客的好处: 写博客,你可以自己定义JS,CSS,图片,嵌入iframe 显示代码示例,什么你都可以自定义,什么标签都允许,而在其他的技术博客站点,因为安全限制,很多是不允许的。
<p>如果你对学习Git,以及使用这种强大的工具和项目/代码管理思想感兴趣,那么推荐你阅读这一系列的文章,讲得深入浅出,生动有趣: <a target=_blank target=”_blank” href=”http://www.worldhello.net/gotgithub/01-explore-github/010-what-is-github.html”>http://www.worldhello.net/gotgithub/01-explore-github/010-what-is-github.html</a></p><p>Windows下Git使用入门系列: 
</p><p></p><ol style="color: rgb(51, 51, 51); font-family: Arial; font-weight: bold; line-height: 26px; font-size: 14px;"><li><a target=_blank target=”_blank” href=”http://blog.csdn.net/renfufei/article/details/41647773” style=”color: rgb(51, 102, 153); text-decoration: none;”>目录</a></li><li><a target=_blank target=”_blank” href=”http://blog.csdn.net/renfufei/article/details/41647875” style=”color: rgb(51, 102, 153); text-decoration: none;”>安装及配置Git</a></li><li><a target=_blank target=”_blank” href=”http://blog.csdn.net/renfufei/article/details/41647937” style=”color: rgb(51, 102, 153); text-decoration: none;”>安装及配置TortoiseGit</a></li><li><a target=_blank target=”_blank” href=”http://blog.csdn.net/renfufei/article/details/41647973” style=”color: rgb(51, 102, 153); text-decoration: none;”>Git与TortoiseGit基本操作</a></li><li><a target=_blank target=”_blank” href=”http://blog.csdn.net/renfufei/article/details/41648021” style=”color: rgb(51, 102, 153); text-decoration: none;”>MarkDown示例</a></li><li><a target=_blank target=”_blank” href=”http://blog.csdn.net/renfufei/article/details/41648061” style=”color: rgb(51, 102, 153); text-decoration: none;”>解决 TortoiseGit 诡异的 Bad file number 问题</a></li></ol>
<p></p>