建立分支
git init
git remote add origin git@github.com:m2kar/m2kar.github.io.git
git checkout -b blog
git add .
git commit -m "first commit"
git push -u origin blog
分支配置
在博客分支中配置 .travis.yml
language: go
go:
- master
branches:
only:
- hugo
install:
- curl -LO https://github.com/spf13/hugo/releases/download/v0.18.1/hugo_0.18.1_Linux-64bit.tar.gz
- tar zxf hugo_0.18.1_Linux-64bit.tar.gz
- sudo mv hugo_0.18.1_linux_amd64/hugo_0.18.1_linux_amd64 /bin/hugo
script:
# 运行hugo命令
- hugo
after_script:
# 部署
- cd ./public
- git init
- git config user.name "hank-leo"
- git config user.email "ihankleo@gmail.com"
- git add .
- git commit -m "Update Blog By TravisCI With Build $TRAVIS_BUILD_NUMBER"
# Github Pages
- git push --force --quiet "https://$GITHUB_TOKEN@${GH_REF}" master:master
# Github Pages
- git push --quiet "https://$GITHUB_TOKEN@${GH_REF}" master:master --tags
env:
global:
# Github Pages
- GH_REF: github.com/hank-leo/hank-leo.github.io.git
deploy:
provider: pages # 重要,指定这是一份github pages的部署配置
skip-cleanup: true # 重要,不能省略
local-dir: public # 静态站点文件所在目录
target-branch: master # 要将静态站点文件发布到哪个分支
github-token: $GITHUB_TOKEN # 重要,$GITHUB_TOKEN是变量,需要在GitHub上申请、再到配置到Travis
# fqdn: # 如果是自定义域名,此处要填
keep-history: true # 是否保持target-branch分支的提交记录
on:
branch: master # 博客源码的分支
切换分支
1.切换到文件目录下git branch -a
查看是否存在分支
Hanks-Air:hank-leo Hank$ git branch -a
* hugo
remotes/origin/hugo
2.切换到想要到的分支 git checkout 分支名
Hanks-Air:hank-leo Hank$ git checkout hugo
deploy.sh
public
static/.DS_Store
themes/maupassant
已经位于 'hugo'
您的分支与上游分支 'origin/hugo' 一致。
3.检查是否切换成功,查看当前分支
Hanks-Air:hank-leo Hank$ git branch
* hugo
删除分支
删除远程分支
git push origin --delete <branchName>
也可以推送一个空分支到远程分支,相当于删除远程分支
git push origin : <branchName>