Make sure you have these locally:
git --version
cargo --versionInstall mdBook if you don’t have it:
cargo install mdbook-
Go to https://github.com/new
-
Fill in:
- Repository name:
my-mdbook(or whatever you like) - Visibility: Public (required for free GitHub Pages)
- Repository name:
-
✅ Do NOT check “Add a README”
-
Click Create repository
Keep that page open — GitHub will show you the repo URL.
mkdir my-mdbook
cd my-mdbook
mdbook initChoose:
srcdirectory? → yes- Create
.gitignore? → yes
Test locally:
mdbook serveOpen http://localhost:3000 to confirm it works.
Stop the server (Ctrl+C).
Inside your book directory:
git init
git add .
git commit -m "Initial mdBook"Add the remote (replace with your GitHub username):
git branch -M main
git remote add origin https://github.com/<your-username>/my-mdbook.git
git push -u origin main✅ You now have:
- A GitHub repo
- mdBook source code on
main
We’ll let GitHub build and publish the book automatically.
mkdir -p .github/workflowsCreate .github/workflows/deploy.yml:
name: Deploy mdBook to GitHub Pages
on:
push:
branches:
- main
permissions:
contents: read
pages: write
id-token: write
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
- name: Install mdBook
run: cargo install mdbook
- name: Build book
run: mdbook build
- name: Upload Pages artifact
uses: actions/upload-pages-artifact@v3
with:
path: book
deploy:
needs: build
runs-on: ubuntu-latest
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4Commit and push:
git add .github
git commit -m "Deploy mdBook to GitHub Pages"
git push-
Go to your repo on GitHub
-
Settings → Pages
-
Under Source, select:
- Source: GitHub Actions
-
Save
After the workflow finishes (1–2 minutes), your book will be live at:
https://<your-username>.github.io/my-mdbook/
Edit files in src/:
src/SUMMARY.md→ table of contentssrc/chapter_1.md→ content
Then:
git add .
git commit -m "Update book content"
git pushGitHub Pages updates automatically.