Fedora下克隆Octopress博客

      我在自己的github上搭建了一个Octopress博客(http://songlee24.github.io/),用于不定期的写一些学习笔记和心得体会。但是有时候由于换了电脑或者重装了linux系统,就需要重新从github上克隆博客仓库到本地。

      最近从Ubuntu转战Fedora,为了在Fedora上继续写博客,需要把博客克隆下来,这里做个笔记,以备后用:

一,安装git,重新创建SSH密钥

        因为重装了系统,首先需要安装git,这个可以参考github官方教程,在fedora上安装git命令行:

sudo yum install git
git config --global user.name "SongLee24"
git config --global user.email "lisong.shine@qq.com"
git config --global credential.helper cache
git config --global credential.helper 'cache --timeout=3600'

另外,SSH密钥要重新创建添加,参见创建ssh密钥官方教程,命令行:

cd ~/.ssh/   #进入目录
ls -al
ssh-keygen -t rsa -C "lisong.shine@qq.com"  #创建新的ssh密钥
ssh-add ~/.ssh/id_rsa   #添加新ssh密钥到ssh-agent

注意创建密钥的时候,提示需要“Enter a file in which to save the key”,点击确定就行了,接着会继续要你输入口令(Passphrase),输入你自己的口令。然后,你会发现.ssh文件夹下生成了id_rsa和id_rsa.pub两个文件,将id_rsa.pub文件里面的内容复制到Github的Account Settings里的Add SSH key.

测试是否成功:

ssh -T git@github.com

会需要输入你的口令,然后如果输出下面的信息,表示一切成功:

The authenticity of host 'github.com (207.97.227.239)' can't be established.
RSA key fingerprint is 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48.
Are you sure you want to continue connecting (yes/no)?
Hi username! You've successfully authenticated, but GitHub does not provide shell access.

二,安装Ruby

      Fedora上使用RVM,而不是Yum安装最新版本的Ruby。之所以不用Yum,是因为Fedora的Yum源没有Ruby 1.9.3。

#1,安装rvm
$ curl -L get.rvm.io | bash -s stable
#2,使rvm命令生效
$ source ~/.rvm/scripts/rvm
#3,查看可用的ruby版本
$ rvm list known
#4,我安装的是最新版Ruby2.0.0,我应该安装Ruby1.9.3的
$ rvm install 2.0.0

然后是更换Ruby的更新源,因为某些原因。

#查看当前的gem源
$ gem sources -l
#删除该gem源
$ gem sources -r https://rubygems.org/
#添加taobao的源
$ gem sources -a http://ruby.taobao.org/

这个时候,如果你运行下面的命令:

gem install bundler
bundle install

你会发现执行bundle install的时候会出现“Could not locate Gemfile”的错误提示,在网上查了好多资料,说是在你执行命令的文件夹下没有Gemfile文件,所以需要先进入一个项目。于是我先跳到第三步。

三,拉取Octopress仓库内容

      1. 创建你要放置博客仓库的目录,然后进入文件夹:

cd MyBlog/octopress/
git init
git remote add origin git@github.com:SongLee24/songlee24.github.com.git
git pull origin

初始化git仓库,添加远程仓库,也就是你自己的github博客仓库地址,pull远程仓库。

     2. 然后,切换到source分支,建立github pages:

git checkout source        #切换分支
rake setup_github_pages    #建立pages

在执行rake setup_github_pages的时候会出现以下提示:

Could not find rake-0.9.2.2 in any of the sources
Run `bundle install` to install missing gems.

这个时候再执行命令bundle install

OK,成功!

这时候再执行rake setup_github_pages,提示如下:

You have already activated rake 0.9.6, but your Gemfile requires rake 0.9.2.2. Prepending `bundle exec` to your command may solve this.

因为rake版本不一致,所以命令运行不成功。根据提示我在命令前面加上bundle exec

bundle exec rake setup_github_pages

然后它会叫你输入URL:

Enter the read/write url for your repository
(For example, 'git@github.com:your_username/your_username.github.io.git)
           or 'https://github.com/your_username/your_username.github.io')
Repository url: git@github.com:SongLee24/songlee24.github.com.git
rm -rf _deploy
mkdir _deploy
cd _deploy
初始化空的 Git 版本库于 /home/songlee/MyBlog/octopress/_deploy/.git/
[master(根提交) 594aab2] Octopress init
 1 file changed, 1 insertion(+)
 create mode 100644 index.html
cd -

---
## Now you can deploy to git@github.com:SongLee24/songlee24.github.com.git with `rake deploy` ##

终于执行成功!这时候octopress目录下生成了_deploy文件夹。

     3. 切换到master分支,进入_deploy目录,拉取master分支:

git checkout master
cd _deploy/
git pull origin master

然后pull的时候又出现了问题,文件index.html出现冲突,当你执行bundle exec rake deploy的时候也提示说:Pull 不可用,因为您尚有未合并的文件。请先在工作区改正文件,然后酌情使用 'git add/rm <file>' 标记解决方案,或者使用 'git commit -a'。

于是运行下面的命令合并冲突

git add index.html
git commit -m "合并冲突"

这时候再执行rake generate和rake deploy发现一切正常了。博客成功克隆到本地,以后就可以正常写博文并提交到Github上了。


附 博客添加和修改后提交的日常命令

rake new_post['Blog Name']

rake generate   
rake deploy

git add .  
git commit -m "commit message"  
git push origin source



我的Github博客:http://songlee24.github.com



原文地址:https://www.cnblogs.com/songlee/p/5738155.html