Git deployer plugin for Hexo.
Update Git for Windows to the latest version. (Details)
$ npm install hexo-deployer-git --save
You can configure this plugin in _config.yml
.
# You can use this:
deploy:
type: git
repo: <repository url>
branch: [branch]
message: [message]
name: [git user]
email: [git email]
extend_dirs: [extend directory]
ignore_hidden: false # default is true
ignore_pattern: regexp # whatever file that matches the regexp will be ignored when deploying
# or this:
deploy:
type: git
message: [message]
repo:
# both formats are acceptable
[repo host name]: <repository url>[,branch]
[another repo]:
url: <repository url>
branch: [branch]
token: [$ENV_TOKEN]
extend_dirs:
- [extend directory]
- [another extend directory]
ignore_hidden:
public: false
[extend directory]: true
[another extend directory]: false
ignore_pattern:
[folder]: regexp # or you could specify the ignore_pattern under a certain directory
# keys inside repo do not matter, and can be omitted for single repo with token:
deploy:
repo:
url: <repository url>
token: [$ENV_TOKEN]
# ...your other configs
- repo: Repository settings, or plain url of your repo
- REPO_NAME: Name for each of your repo setting. This layer can be omitted for single repo config.
- url: Url of your repositury to pull from and push to.
- branch: Optional git branch to deploy the static site to.
- token: Optional plain-text personal access token to auth push action, or a string starting with
$
to read token from environment varable. For details.
- REPO_NAME: Name for each of your repo setting. This layer can be omitted for single repo config.
- branch: Git branch to deploy the static site to. Would be overridden if branch in repo is configed.
- message: Commit message. The default commit message is
Site updated: {{ now('YYYY-MM-DD HH:mm:ss') }}
. - name and email: User info for committing the change, overrides global config. This info is independent of git login.
- extend_dirs: Add some extensions directory to publish. e.g
demo
,examples
- ignore_hidden (Boolean|Object): whether ignore hidden files to publish. the github requires the
.nojekyll
in root.- Boolean: for all dirs.
- Object: for public dir and extend dir:
public
: the public dir defaults.- [extend directory]
- ignore_pattern (Object|RegExp): Choose the ignore pattern when deploying
- RegExp: for all dirs.
- Object: specify the ignore pattern under certain directory. For example, if you want to push the source files and generated files at the same time to two different branches. The option should be like
# _config.yaml deploy: - type: git repo: git@github.com:<username>/<username>.github.io.git branch: master - type: git repo: git@github.com:<username>/<username>.github.io.git branch: src extend_dirs: / ignore_hidden: false ignore_pattern: public: .
It might be dangerous to save your account info in repo url, or a private key in deployment environment like public CI server. You can authorize the push action of deployment in repo.token
config.
- To learn more about personal access token and how to generate it, follow the guide of creating a personal access token in Github or consult your repo host.
- To check how to save your token in environment secretly, follow the guide of virtual environments for GitHub Actions or consult your ci server host.
Token is only effective in the repo with a http(s) url.
hexo-deployer-git
works by generating the site in .deploy_git
and force pushing to the repo(es) in config.
If .deploy_git
does not exist, a repo will initialized (git init
).
Otherwise the curent repo (with its commit history) will be used.
Users can clone the deployed repo to .deploy_git
to keep the commit history.
git clone <gh-pages repo> .deploy_git
Remove .deploy_git
folder.
$ rm -rf .deploy_git
MIT