git部署博客源码
- 在blog/config文件里面确定了hexo s将博客部署到仓库的main分支,但是部署的是渲染后的代码,如何保存源码进行备份。
1 创建分支
在blog下打开gitbash
1 | git init |
去掉blog/.gitignore文件中这三项:
1 | db.json, |
- 由于使用了yilia主题,相当于你的blog项目下包含了一个子项目:yilia,需要将themes/yilia里面的一些文件去掉,否则themes/yilia里面的内容不会被提交到远程仓库。
1
2
3cd themes/yilia
rm -rf .git
git rm -r --cached
运行
1 | git add * |
创建一个source分支,上传源码(注意此处仓库地址,参考blog/config文件里面的部署部分,是带@符号的那个名字,不是简单的博客地址)
1 | git checkout -b source |
2 设置默认分支
建议将source分支设置成默认分支,防止误删
以后只需要执行:
1
2
3
4git add .
git commit -m "Your commit message"
git push -u github source
3 在新设备上编写博客
在设备上生成ssh密钥
1
ssh-keygen
- 然后一路回车,会在:user/.ssh下面有id_rsa和id_rsa.pub。
将id_rsa.pub内容复制到github中:
- 在github点击右上角自己的图像
- settings
- 左侧SSH and GPG keys
- 右侧:New SSH key
在设备上提供github用户名和邮箱
- 用户名可以在右上角头像获得
- 邮箱可以通过setting -> email获得
1
2git config --global user.name "Your Name"
git config --global user.email "you@example.com"
拉取博客
1
2
3
4
5
6mkdir blog
cd blog
git init
git checkout -b source
git remote add github 远程仓库地址
git pull github source上传博客
1
2
3git add .
git commit -m "提示"
git push --set-upstream github source