In this section we will create a local git repository manage changes to the important files and directories in your Hexo website project. Those changes will be copied to a repository on Github, becoming an exact copy in the cloud.
Whist this step is optional it provides many benefits. Its a good way to back up your content to somewhere relatively safe (in terms of your laptop going bang). Using a distributed version control system like Github also makes it really easy to collaborate with others, allowing them to submit content for new articles and corrections for existing content.
So lets set up your Hexo website content under version control using Git and Github.
Git is available from the Git website. Download and install the approprate version for your operating system.
On Ubuntu systems you can install Git using the package manager
sudo apt-get install git
Once installed you can test git is working using the following command in a terminal:
To understand who as created which change in Git, you should configure your name and email address (your email address should be the one you use for Github in the next step)
git config --global user.name "YOUR NAME" git config --global user.email "YOUR EMAIL ADDRESS"
Visit the Gihub website in your browser and follow the steps to create an account (or login if you already have an account).
Add your public key to your Github account, see the Github Help pages on SSH Keys.
Now we are going to create a Git repository within your Hexo project. The repository will contain the full history of every change you add to git.
Inside your hexo-website folder, use the command
Add the important files to Git and then commit those files as the first change:
git add _config.yml packages.json .gitignore scaffolds/*.md git commit -m "Adding a new Hexo website"
Sign into your account on Github and create a new repository
Once your new repository has been created, Github shows you the details for accessing it.
Add this new repository to your local git repository
git remote add origin firstname.lastname@example.org:jr0cket/jr0cket.github.io-hexo.git
Now copy all your changes that have been commited in your local Git repository to the Github repository.
git push origin master
By convention, the name origin is used to refer to the canonical Git repository for the project. Origin is only an alias for the repository URL, so you can use what ever name you like for the alias so long as its unique for your local repository and you use the same name for
git remote addand
When you make more changes to your project, add those changes to your local Git repository and then send them to Github.
git add filename git commit -m "description of the change" git push origin master
Should the worst happen - your laptop goes bang or your project is accidently deleted - you can easily recover all the changes you pushed to Github with a single command:
git clone origin email@example.com:jr0cket/jr0cket.github.io-hexo.git
This work is licensed under a Creative Commons Attribution 4.0 ShareAlike License, including custom images & stylesheets. Permissions beyond the scope of this license may be available at @jr0cket