计算机‎ > ‎网络‎ > ‎

用 git 在 gitcafe 和 bitbucket 创建 个人/项目 博客

发布者:guo rue,发布时间:2014年6月13日 21:14   [ 更新时间:2014年6月14日 07:21 ]
和在《用 git 在 github 创建 个人/项目 主页》类似,这篇也是用 git 这个软件,目前 gitcafe 提供和 github 一样的 pages ,但是托管商 bitbucket 相对于 github/gitcafe 有一个优势在于可以建立非公开的 repo ,遗憾的是这个 repo 是不能绑定域名的。只能是一个二级地址。

我决定用 gitcafe 创建一个 repo 绑定 blog.guoruei.net 这个二级域名,然后页面转跳到 guoruei.bitbucket.org 这个 repo 去,这个 bitbucket 我用来做博客。

好的,先注册 gitcafe 这里会提示你,安装并设置 Git 到您的电脑
apt-get install git-core

进入 SSH 目录
cd ~/.ssh
如果还没有 ~/.ssh 目录的话,请先手工创建一个
mkdir ~/.ssh

生成新的 SSH 秘钥

如果你已经有了一个秘钥(默认秘钥位置~/.ssh/id_rsa文件存在),但是你想在 GitCafe 网站上使用另一套秘钥,请查看 如何同时使用多个公秘钥
记得把以下命令中的 YOUR_EMAIL@YOUREMAIL.COM 改为你的 Email 地址
ssh-keygen -t rsa -C "YOUR_EMAIL@YOUREMAIL.COM"
生成过程中会出现以下信息,按屏幕提示操作,并记得输入 passphrase 口令。
ssh-keygen -t rsa -C "YOUR_EMAIL@YOUREMAIL.COM"
Generating public/private rsa key pair.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /c/Users/USERNAME/.ssh/id_rsa.
Your public key has been saved in /c/Users/USERNAME/.ssh/id_rsa.pub.
The key fingerprint is:
15:81:d2:7a:c6:6c:0f:ec:b0:b6:d4:18:b8:d1:41:48 YOUR_EMAIL@YOUREMAIL.COM
SSH 秘钥生成结束后,你可以在用户目录 (~/.ssh/) 下看到私钥 id_rsa 和公钥 id_rsa.pub 这两个文件,记住千万不要把私钥文件 id_rsa 透露给任何人。

添加 SSH 公钥到 GitCafe
用文本工具打开公钥文件 ~/.ssh/id_rsa.pub ,复制里面的所有内容到剪贴板。
进入 GitCafe -->账户设置-->SSH 公钥管理设置项,点击添加新公钥 按钮,在 Title 文本框中输入任意字符,在 Key 文本框粘贴刚才复制的公钥字符串,按保存按钮完成操作。

测试连接
以上步骤完成后,你就可以通过以下命令来测试是否可以连接 GitCafe 服务器了。
ssh -T git@gitcafe.com

如果是第一次连接的话,会出现以下警告,
The authenticity of host 'gitcafe.com (50.116.2.223)' can't be established.
#RSA key fingerprint is 84:9e:c9:8e:7f:36:28:08:7e:13:bf:43:12:74:11:4e.
#Are you sure you want to continue connecting (yes/no)?
如果没有问题,输入 yes 按回车就可以了。
中间会提示你输入 passphrase 口令。
Enter passphrase for key '/c/Users/USERNAME/.ssh/id_rsa':
最后,如果连接成功的话,会出现以下信息。
Hi USERNAME! You've successfully authenticated, but GitCafe does not provide shell access.
完成

测试通过后,你就可以到 GitCafe 上创建 Git 项目并上传代码了。
接着。创建一个与用户名(如果是组织,就是组织名)相同名称的项目。
全局设置:
git config --global user.name 'GReat Nong'
git config --global user.email 'nong@guoruei.net'
接下来:
? 在本地创建新的 Git 仓库
cd /var/www
mkdir gitcafe
cd gitcafe
git clone https://gitcafe.com/guoruei/guoruei.git
git init
nano README.md
git add README.md
git commit -m 'first commit'
git remote add origin 'git@gitcafe.com:guoruei/guoruei.git'
git push -u origin master

? 在本地已有 Git 仓库
cd existing_git_repo
git remote add origin 'git@gitcafe.com:guoruei/guoruei.git'
git push -u origin master
这里会问你要passphrase,输入之前生成新的 SSH 秘钥时候写的passphrase
当你完成的时候:
点 继续
浏览器访问 guoruei.gitcafe.com
显示
404
Ooooops, page can't be found.
我们回头去建立一个试验性的html文档
nano index.html
输入
<script>window.location.href='http://guoruei.bitbucket.org';</script>
退出保存,然后
git add .
git commit -a -m 'html test'
git remote add origin 'git@gitcafe.com:guoruei/guoruei.git'
git checkout -b gitcafe-pages
git push origin gitcafe-pages
这里会问你要passphrase,输入之前生成新的 SSH 秘钥时候写的passphrase

这样,guoruei.gitcafe.com 已经转跳到 guoruei.bitbucket.org 了。现在 要去给 guoruei.gitcafe.com 设置自定义域名到 blog.guoruei.net

查看项目 https://gitcafe.com/guoruei/guoruei 点击项目管理——自定义域名——新增 blog.guoruei.net

然后去域名服务商 域名管理页面增加一条 A 记录, 将它指向 GitCafe 服务器的 IP 地址 117.79.146.98

这样 gitcafe 部分就算 OK 了。下面是 bitbucket 部分

注册一个 bitbucket 账户:guoruei 。和一般网站注册差不多。新建一个 repo 名字就是 guoruei.bitbucket.org 了。好的。注意选择 非公开的哟。
在网页目录下面创建目录
cd /var/www/
mkdir bitbucket
cd bitbucket
把在 bitbucket 创建的 repo 拉下来
git clone https://guoruei@bitbucket.org/guoruei/guoruei.bitbucket.org.git
进入网站文件夹编辑首页
cd guoruei.github.com
nano index.html
编辑后保存退出。
建立提交。
git add index.html
git commit -m "test 1"
推送到 bitbucket,完成远程版本库更新。
git push origin master

好的,打开浏览器,试着访问一下 guoruei.bitbucket.org ,好的。再试一下 blog.guoruei.net  自动跳到 guoruei.bitbucket.org 了,嗯,好的。

gitcafe 部分参考
https://gitcafe.com/GitCafe/Help/wiki/如何安装和设置-Git#wiki
http://blog.gitcafe.com/116.html
http://blog.gitcafe.com/142.html

bitbucket 部分参考
https://confluence.atlassian.com/display/BITBUCKET/Associate+an+existing+domain+with+an+account
https://confluence.atlassian.com/display/BITBUCKET/Publishing+a+Website+on+Bitbucket
https://bitbucket.org/site/master/issue/2184/support-cnames-for-repositories-bb-3655