Getting Started · Free guide

Beginner checklist: connecting GitHub and Cloudflare Pages cleanly

A clean GitHub + Cloudflare Pages setup puts your site in its own repository on branch main, grants Cloudflare access to that single repository only, pins your Node version, verifies the live *.pages.dev preview URL first, and tests one automatic rebuild commit before attaching a custom domain.

By StaticLaunch · Four Media Group LLC

Step 1: Lock down both accounts with 2FA first

Before creating repositories or DNS zones, enable authenticator-app two-factor authentication on both your GitHub and Cloudflare logins and store printed recovery codes somewhere offline.

  • Never share one login across team members—invite collaborators individually.
  • Verify your billing/admin email belongs to you, not a temporary contractor.

Step 2: Create a single-purpose website repository

Keep one repository per website so permissions, pull requests, and deployment previews stay isolated. Commit package-lock.json and .node-version alongside astro.config.mjs and public/_headers.

Step 3: Scope Cloudflare GitHub authorization narrowly

When authorizing the Cloudflare Workers & Pages GitHub App, choose 'Only select repositories' rather than granting read/write access across every private repo in your account.

Step 4: Configure exact build & output settings

Set production branch to main, build command to npm run build (blank for raw HTML), and output directory to dist (or / for raw HTML). Confirm your staging site loads properly at https://project-name.pages.dev.

Example
Production branch: main
Build command: npm run build
Build output directory: dist
Node compatibility: .node-version (22.23.4)

Step 5: Verify a second commit + rollback before DNS

Make one tiny text edit, push to main, confirm Cloudflare rebuilds automatically, and verify Deployments → Rollback works. Only then attach your custom domain.

Common questions

Do I have to use Wrangler CLI to deploy to Cloudflare Pages?

No. Connecting GitHub triggers cloud builds automatically on every push to main, though Wrangler is helpful for local previewing or Direct Upload folders.

What happens if a bad commit breaks layout?

In Cloudflare Pages Deployments, click the previous green deploy and choose Rollback to restore the prior build in seconds while you fix main cleanly.

References

Provider interfaces and limits can change. Consult the original documentation before changing production settings.