Git分支管理Hexo

1.本地初始电脑

1.初始化Git仓库

1
2
$ cd blog
$ git init # 创建.git子目录

2.添加远程仓库

1
$ git remote add origin git@github.com:yourname/yourname.github.io.git

3.拉取远端仓库所有内容及分支

1
$ git fetch origin

5.新建分支

1
$ git checkout -b master

4.在./source/_post/中添加.md博客并生成

1
2
3
$ hexo clean
$ hexo g
$ hexo d

5.将本地仓库推送至远端

1
$ git push origin master

2.其他电脑

1.安装Node.js

2.拉取远端仓库并进入文件夹

1
2
$ git clone git@github.com:yourname/yourname.github.io.git blogname
$ cd blogname

3.拉取远端仓库分支并切换至master分支(默认分支是main,master分支是自己建的)

1
2
$ git fetch origin
$ git checkout master

4.安装Hexo及相关依赖

1
2
3
$ npm install hexo	# 安装hexo
$ npm install hexo-cli -g # 重新安装(如果上述安装不起作用)
$ npm install # 安装依赖

5.安装deploy-git

1
$ npm install hexo-deployer-git --save

6.在./source/_post/中添加.md博客并生成

1
2
3
$ hexo clean
$ hexo g
$ hexo d

8.将本地仓库推送至远端

1
$ git push origin master

3.更换主题

1.进入./themes文件夹

2.github上clone喜欢的主题

1
$ git clone git@github.com:xxx/xxx.git file-name

3.进入file-name文件夹

4.删除.git文件夹

1
$ rm -r .git

5.修改最外层目录下的_config.yml文件
theme: file-name

6.修改.gitignore文件(或者把里面内容删掉也行)

7.将本地仓库推送至远端

1
2
3
$ git add .
$ git commit -m "add theme"
$ git push origin master

ps.修改好主题之后,主题配置在file-name文件夹中的_config.yml中进行配置。

4.说明

main分支用来部署博客:当执行hexo d的时候,博客部署在main分支,不需要执行git push origin main,因为hexo d指令已经将相应的html文件推送到远端服务器的main分支上了。
master分支用来存储文件:比如.md文件,存放在./source/_post文件夹中,最后需要手动执行git push origin master


Git分支管理Hexo
http://example.com/2025/02/22/blog/Git分支管理Hexo/
作者
ZhangHangming
发布于
2025年2月22日
许可协议