This blog is an example. It was built with Astro 7.4.13. Its code lives in the Kodename-jpg.github.io repo on GitHub. You can build the same blog, for free. Follow the steps below.

A static blog holds only HTML, CSS, and image files. It has no database. It also has no server. GitHub Pages is a free hosting service from GitHub. Every step here is free. You do not need a credit card.

Astro blog to GitHub Pages flow

Figure 1: The Astro blog to GitHub Pages flow — from writing on your laptop to a live blog.

What You Need

  • A GitHub account (free, sign up at github.com).
  • Node.js version 22 or newer.
  • A text editor, for example VS Code.
  • A terminal.

Step 1: Install Node.js on Arch Linux

Node.js is a program that runs JavaScript on your computer. Astro needs Node.js to work. Install it with pacman, the package installer on Arch Linux.

sudo pacman -S nodejs npm

npm is a tool for installing JavaScript packages. The npm package comes with the command above. Check the versions:

node --version
npm --version

The node –version result must be v22 or newer. Astro needs Node.js v22.23.4 or newer. Odd versions like v23 are not supported.

Step 2: Create an Astro Project

Run this command in your terminal. It opens a wizard, a guide that asks you questions step by step.

npm create astro@latest

The wizard will ask a few things. Type blog-saya as the folder name. Choose the Blog template if you want a ready-made blog example. A template is the starting shape of a project. Answer y when asked to install dependencies and init git. Dependencies are extra packages the project needs. Git is a tool for sending files to GitHub.

Enter the project folder:

cd blog-saya

Step 3: Run the Dev Server

A dev server is a small server on your laptop for previewing the blog as you write. Run this command:

npm run dev

Open http://localhost:4321 in your browser. Localhost is your own computer’s address. Every time you save a file, the page updates at once. Press Ctrl+C to stop.

Step 4: Write Your First Page

Astro blog project structure

Figure 2: The Astro blog project structure — pages in src/pages, articles in src/content, images in public.

The file src/pages/index.astro is your blog’s home page. An .astro file is an Astro page file. Fill it with this example:

---
---
<h1>My blog</h1>
<p>Hello, this is my first blog.</p>

Articles are written in Markdown format. Markdown is a simple text format for writing articles. Save articles in the src/content/ folder. Save images and other files in the public/ folder.

Step 5: Build the Project

A build turns your project into finished HTML files. Run this command:

npm run build

The result goes into the dist/ folder. The dist/ folder holds the finished HTML files, ready for hosting.

Warning: If the build fails on your laptop, it will also fail on GitHub. Fix it first until npm run build passes on your laptop.

Step 6: Create a GitHub Repository

A repository is a place to store project files on GitHub. Log in to GitHub first. Click the + button at the top right. Choose New repository. Fill in Repository name with username.github.io. Replace username with your GitHub username. Choose Public. Click Create repository.

Warning: The repo name must be exactly username.github.io, all lowercase. A single wrong letter breaks the blog address. This is GitHub’s rule for a user site.

Tips: If you want a second blog, the repository name is free, for example blog-saya. Its address will be username.github.io/blog-saya. That is called a project site.

Step 7: Push the Project to GitHub

A push sends files from your laptop to GitHub. Run these commands in the project folder:

git init
git add .
git commit -m "First blog"
git remote add origin https://github.com/username/username.github.io.git
git push -u origin main

Replace username with your GitHub username in the remote add origin line.

Warning: Do not upload secrets like passwords or API keys to a public repository. An API key is a secret code for using a service. Everyone can see the contents of a public repository.

Step 8: Set Up astro.config.mjs

The file astro.config.mjs is the Astro project’s settings file. Set site to your blog’s address. Open the file and change it to look like this:

import { defineConfig } from 'astro/config'

export default defineConfig({
  site: 'https://username.github.io',
})

Replace username with your GitHub username. For a user site, you do not need to set base. base is only needed for a project site, a repo with a free name.

Step 9: Add the Automatic Deploy File

Create a new file in your project named .github/workflows/deploy.yml. This file tells GitHub to build and publish your blog every time you push. Fill it with the official YAML from Astro:

name: Deploy to GitHub Pages

on:
  # Trigger the workflow every time you push to the `main` branch
  # Using a different branch name? Replace `main` with your branch's name
  push:
    branches: [ main ]

  # Allows you to run this workflow manually from the Actions tab on GitHub.
  workflow_dispatch:

# Allow this job to clone the repo and create a page deployment
permissions:
  contents: read
  pages: write
  id-token: write

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout your repository using git
        uses: actions/checkout@v7
      - name: Install, build, and upload your site
        uses: withastro/action@v6
        # with:
          # path: . # The root location of your Astro project inside the repository. (optional)
          # node-version: 24 # The specific version of Node that should be used to build your site. Defaults to 24. (optional)
          # package-manager: pnpm@latest # The Node package manager that should be used to install dependencies and build your site. Automatically detected based on your lockfile. (optional)

  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@v5

Commit and push this file as usual:

git add .
git commit -m "Add automatic deploy"
git push

Step 10: Enable GitHub Pages

Enable GitHub Pages

Figure 3: The GitHub Pages settings — choose GitHub Actions as the Source.

Go to the Settings tab in your repository. Choose Pages in the left menu. Under Source, choose GitHub Actions. Do not choose Deploy from a branch. Deploy from a branch is only for plain HTML blogs, not Astro.

Step 11: Open Your Blog

Wait about 1 minute until GitHub finishes building your blog. Then open its address:

https://username.github.io/

Replace username with your GitHub username.

Tips: If the page does not show yet, wait a moment and refresh. The first GitHub Pages build usually takes about 1 minute.

Update the Blog

To change your blog, edit the files on your laptop. Then push again with Git. GitHub Pages will rebuild your blog automatically in about 1 minute. You do not need to repeat the setup steps above.

References

  1. https://docs.astro.build/en/install-and-setup/
  2. https://docs.astro.build/en/guides/deploy/github/
  3. https://docs.github.com/en/pages/quickstart
  4. https://docs.github.com/en/pages/getting-started-with-github-pages/creating-a-github-pages-site