0%

The background is i have to access both github and company git account on my working computer, i wish it can switch git account automatically.

Generate ssh pub & private key

1
$ ssh-keygen -t rsa -C "your_github_email@example.com"

Add ssh pub key to github settings

Create independence ssh configuration file for different git account

1
2
3
4
root directory:~\\.ssh 
- /company/.gitconfig-company
- /github/.gitconfig-github
- .config

Set configuration file

1
2
3
4
5
.gitconfig-company

[User]
name = username
email = company git account email
1
2
3
4
5
.gitconfig-github

[User]
name = username
email = github account email
1
2
3
4
5
6
7
8
9
10
11
12
.config

#git for company
Host
User
IdentityFile ~/.ssh/company/zhaowh3_rsa

#git for github
Host github.com
HostName github.com
User git
IdentityFile ~/.ssh/github/id_rsa_github

Welcome to my blog! This is my very first post. It records the steps about how to setup personal blog site on github and how to use travis CI to auto deploy the changes.

Steps

Create a new repo and push to github

1
repo must be named account_name.github.io

Init hexo

1
2
3
$ hexo init blog
$ cd blog
$ npm i

Update _config.yml for common

1
url: https://username.github.io

Update _config.yml for deploy

1
2
3
4
deploy:
type: git
repo: git@github.com:username/username.github.io.git
branch: gh-pages

Update theme

1
2
3
npm i hexo-theme-next --save

copy _config.next.yml to the root directory

or

1
2
3
$ cd hexo
$ git clone https://github.com/theme-next/hexo-theme-next themes/next

1
2
modify _config.yml as below
theme: next

Generate static files

1
2
$ hexo clean
$ hexo generate

Deploy to remote sites manually

1
2
$ npm i hexo-deployer-git
$ hexo deploy

Deploy to remote sites by travis CI

1
2
3
generate githup personal access token
grant github repo permission to travis
add token to travis Environment Variables
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
add .travis.yml 

sudo: false
language: node_js
node_js:
- 16 # use nodejs v10 LTS
cache: npm
branches:
only:
- master # build master branch only
script:
- hexo clean
- hexo generate # generate static files
deploy:
provider: pages
skip-cleanup: true
github-token: $GH_TOKEN
keep-history: true
on:
branch: master
local-dir: public

Customize domain

1
2
3
purchase personal domain from ali yun
parse my github page ip with domain
update new domain in github page of this repo setting page