In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "how to use git branch to save hexo blog source code to github", the content of the article is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "how to use git branch to save hexo blog source code to github" bar!
Hexo is currently the most popular static blog framework, which supports Markdown format article editing and automatic generation of corresponding static web pages. It is simple and efficient. The process of writing a blog using hexo is usually
Through the hexo new post_name command, a post_name.md file to be written is automatically generated in the source/_post directory
After writing the md file, compile and generate the corresponding HTML file with hexo generate
Before publishing, you can use hexo s local preview, and then publish to the master branch of the remote warehouse through hexo deploy, and then your personal site can see the newly added article.
Perplex
However, friends who have used hexo to build personal blogs will probably encounter the problem of blog source code preservation. That is, the remote warehouse will only save the static HTML files released by hexo, and your blog md source files, theme configuration, etc., are still local. Once the computer disk is broken or changed, you will not be able to continue to blog on the basis of the previous warehouse. To solve this problem, many bloggers will set up a separate repository on github to save blog source files. Every time a new article is published, you need to manually upload the md file under source/post to the corresponding repository of the source file, which can solve the problem, but it is always a hassle. Later, I happened to see smart netizens with the help of the git branch to skillfully use the same warehouse to save static web pages and blog source code. I tried it really well, so I summarized it.
Workaround create a new git branch
Because Github Page requires to use the master branch as the source code of the publishing website, we can only use the master branch to save the static web pages generated by hexo. For the blog source code, we can create a new source branch to store. On github, open the warehouse corresponding to Pages, that is, the warehouse named "username.github.io", and create a source branch, as shown below:
Because I have already created a source branch, the following shows that there are currently two branches, master and source, on the repository. The source branch shows a tick, indicating that the default branch of the current repository is source instead of master, as described below.
Change the default branch of the warehouse
All repositories on github initially have a master branch, which is the default branch. For a warehouse project_name, when we download the code through git clone https://github.com/sherlockyb/project_name.git, we actually pull the code corresponding to the default branch master. When we use hexo to write a blog, we usually deal with md source files, and we don't need to pay attention to the master branch code generated by deploy, so we can change the default branch of the warehouse to the source branch that stores the source code, so that what is pulled through git clone is the source branch code.
On the main page of the repository, through Settings-> Branchs, you can see the Tab of Default branch. The default branch displayed is master. You can check source, and then update can set the default branch to source, as shown below:
Associate a local hexo directory with a remote repository
Go to the local hexo project directory, which is the directory where we usually execute commands such as hexo new post, and do the following:
Git remote add origin https://github.com/sherlockyb/sherlockyb.github.io.git push blog source code
Push local md source files, site configuration files, and so on to the source branch. Because we only need to keep the blog source code, other unrelated files do not want to be pushed, and we need to make sure that the .gitignore file is matched, usually as follows:
.DS _ StoreThumbs.dbdb.json*.lognode_modules/public/.deploy*/
Then execute the following command in turn:
Git add .git commit-m'hexo source post'git push origin source delete files such as public (optional)
Because the source branch is newly built from the master branch, the initial code is actually a copy of the master, so the existing public and other deploy-generated files in the master will also be brought along. These are not blog source files. If you also think that the source branch still has some awkwardness, you can delete it locally and then execute it:
Git add .git commit-m'DEL: public things which only for deploy'git push origin source
After the execution, your warehouse will probably look like this:
Later, even if deploy generates a public file when you post a blog, it won't take it with you when you submit the blog source code, because .gitignore ignores it.
New environment
Suppose we change computers and continue to write articles based on the original warehouse in the new environment. Pull the blog source code locally through git clone, and then install and initialize hexo:
After the git clone https://github.com/sherlockyb/sherlockyb.github.io.git sherlockybcd sherlockybnpm install hexonpm install hexo-deployer-git-save// hexo environment is configured, continue to hexo new post_name... as before Matters needing attention
Make sure that hexo deploy pushes the master branch. The _ config.yml file in the hexo directory is usually configured with the destination address of deploy push. This is generally configured as master when you first use hexo, without change:
# Deployment## Docs: https://hexo.io/docs/deployment.htmldeploy: type: git repo: https://github.com/sherlockyb/sherlockyb.github.io.git branch: master
Synchronize updates to the original text
Thank you for reading, the above is "how to use git branch to save hexo blog source code to github" content, after the study of this article, I believe you on how to use git branch to save hexo blog source code to github this problem has a deeper understanding, the specific use of the situation also needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.