使用Github来管理博客源文件

Hosting the source files of the blog (non-hexo generated files) on GitHub for easy synchronization and version control.

  1. Create a new repository on GitHub named blog
  2. Navigate to the blog folder locally and run the command git init to create a repository
  3. Set the remote repository address and update
$git remote add origin git@github.com:imzlp/blog-source.git  
$git pull origin  
  1. Modify the .gitignore file (create it if it doesn’t exist) and add public/ and .deploy/ to it, as these two folders are updated every time generate and deploy, and are not useful for us, so we ignore updates to these two files.
  2. Use the command git add . to stage all files.
  3. Use the command git commit -m “add all files” to commit these files to the local repository.
  4. Use the command git push origin master to push local repository changes to the GitHub repository.

Clone the source files to local

$git clone <address>  

After writing the article, submit it to the remote repository

//Stage all files  
$git add .  
//Commit all files to the local repository  
$git commit -m "messages"  
//Push the changes from the local repository to the GitHub repository  
$git push  

Synchronize the remote repository to local

$git pull  

or

$git fetch  

Push the blog and source program to different branches of the same repository

Since the blog source program is deployed on the local computer, it can be a bit cumbersome to write blog posts after switching computers, so it seems better to also put the source program on GitHub. However, having the blog source program and the blog occupy separate projects feels wasteful (e.g. the blog is hxhb.github.io), so after some effort, I allowed the blog source program and blog to share a repository with different branches for easier management.

Blog Program: Hexo

Since the page branch of the GitHub Pages project is gh-pages, it is necessary to create this branch.
Then fill in the deploy information in the blog source program’s configuration file _config.yml:

deploy:  
  type: git  
  //Repository address  
  repository: git@github.com:imzlp/blog-source.git  
  //Push to gh-pages branch  
  branch: gh-pages  

Save after modifying with your information.
Use the following commands to push:

hexo -g  
hexo d  

or

hexo d -g  

This will push to the gh-pages branch of the remote repository (source program).
That is, push /sources to the gh-pages branch (/sources is the static page generated by hexo, which is our blog)


In summary, using the integrated hexo d command with git and hexo allows you to push the blog source program and the generated blog to different branches.
When writing blog posts, you can separately git the blog source program

git pull origin master  

Then after writing the article, use hexo d -g to push it up.
No need to separately git the gh-pages branch (because the sources directory of the hexo program is the content of gh-pages).
Finally, just push the source program to the remote master branch, and it’s done.

The article is finished. If you have any questions, please comment and communicate.

Scan the QR code on WeChat and follow me.

Title:使用Github来管理博客源文件
Author:LIPENGZHA
Publish Date:2014/11/20 23:52
World Count:2.4k Words
Link:https://en.imzlp.com/posts/55550/
License: CC BY-NC-SA 4.0
Reprinting of the full article is prohibited.
Your donation will encourage me to keep creating!