配置自定義域名
- 如果沒有GitHub賬户,請先註冊賬户,賬户為
username - 如果已有GitHub賬户,但是想修改賬户名 或 修改域名,點擊“Settings”(設置)>>> 點擊“Account”(賬户)>>> Change username
新建倉庫 New repository. 創建新的 username.github.io 倉庫
創建gh-pages
新建倉庫後,會有一個main分支,此時我們需要再創建一個分支gh-pages(或者自己喜歡的分支名字,)
- 如果是基於剛新建完成倉庫建立的
gh-pages裏面是無文件純淨的 - 如果是基於推送代碼建立的
gh-pages是有文件的,如果你想保持一個乾淨的倉庫需要把他們刪了
設置博客使用分支
- 進入新的
username.github.io倉庫 - 選擇 “Settings”
- 選擇 “Branch” 中新建的分支,如gh-pages
創建一個博客文件,如blog,並關聯此項目
git init
git add .
git commit -m "first commit"
git remote add origin https://github.com/newusername/newusername.github.io.git
git push -u origin main
把blog項目打包出dist文件,並推送到gh-pages分支
如果gh-pages分支有問題可先刪除再創建,刪除命令
git push origin --delete gh-pages # 刪除遠程分支
git branch -D gh-pages # 刪除本地分支
基於當前分支的dist文件創建gh-pages分支
git subtree split --prefix dist -b gh-pages
git push origin gh-pages
把dist文件推送到main分支後,再把dist推送到gh-pages
git subtree push --prefix dist origin gh-pages # 無衝突
git push origin `git subtree split --prefix dist main`:gh-pages --force # 有衝突
訪問路徑
https://username.github.io/
創建子項目博客
- 新建倉庫 New repository. 創建新的
任意倉庫,但不能是username.github.io 倉庫 - 其他步驟同上
- 訪問路徑:
https://username.github.io/任意倉庫名/