Mike Xiao

Code For Life.

Deploy git to your Ghost blog

It's been a long time ago since I setup my blog and post the very first article. After coming back to MSU from Hong Kong I was pretty busy in the following spring semester since there are a lot of stuffs going on (credit transfer, exams, endless assignments..etc).

Anyway, I'm back again, let's back to the business. Today I will talk about how to setup git on your own Ghost blog.

Always setup a version control

After successfully setting up Ghost blog, we might still need to make changes on config. It is important to have a version control to keep tracking your change and recover your original files from VPS failure or unexpected error occurs after you make changes. In most cases, we use git as your version control system since it is the most popular system used by developers.

Deploy git to your blog

In this article we will use GitHub as an example.

First of all, install git on your VPS:

sudo apt-get install git

Wait till the installation is done, after you installed git, connect it to your GitHub account:

git config --global user.name "your name"  
git config --global user.email "your email"

Change your name and your email to your GitHub username and email.

To connect, we need to add a ssh key to your GitHub account.

ssh-keygen -t rsa -C "your_email@example.com"

As the same from above, substitute your_email@example.com to the email you used on GitHub. When generating keys there will be an option for ssh passphrase, use any password you want or hit Enter to skip (use without password).

When completed, under /root/.ssh there will be two files: id_rsa.pub and id_rsa, they are public key and private key respectively.

Open id_rsa.pub use nano or vi, copy THE ENTIRE content to your text editor.

Then open your browser and login to GitHub, under Settings, click SSH and GPG keys, in the right panel, click New SSH Key, add any title and paste your key here.

Test your key on VPS, make sure it is working:

ssh -T git@github.com

When you see the information below, means the key is successfully added.

Create a repository on GitHub with any name (i.e MyBlog), then back to VPS, go to the path of your Ghost blog and initialize git.

cd /var/www/ghost
git init

sometimes the path is located at home directory, then we use following instead:

cd ghost
git init

Bind your local repository with your remote repository on GitHub:

git remote add origin git@github.com:your_name/Blog_Name.git 

Substitute your_name/Blog_Name.git with your GitHub username and the name of your repository.

After binding, add all files in your local repository into git and commit:

git add .
git commit -m "message"

Flag -m means add message for this commit, message can be any message (don't forget quotes!).

When you committed all of your work, push all of your changes to the remote repository:

git push origin master

Go to your repository, make sure your changes has been submitted.

Good to go! You have successfully setup git for your blog.