Build Command, Output Directory and Git Deployment
How to connect Git or upload assets, set build command and output directory, and use production and preview deployments on static hosting.
This page summarises Cloudflare Pages documentation on deploying static sites and front-end applications: connecting a Git repository or uploading prebuilt files, telling the platform how to build the project, and how production versus preview URLs are produced.
Git integration: connect a repository and deploy on every push
Section titled “Git integration: connect a repository and deploy on every push”Git integration is the usual path when you want automatic builds after each commit. Pages supports GitHub and GitLab.
Pages offers support for GitHub ↗︎ and GitLab ↗︎. To create your first Pages project:
In the Cloudflare dashboard, go to the Workers & Pages page.
Select Create application > Pages > Connect to Git.
Select GitHub or GitLab. If prompted, authenticate with your Git provider. This allows Cloudflare Pages to deploy your projects and update your pull requests with preview deployments.
After you pick a repository and complete Install & Authorize and Begin setup, you configure Set up builds and deployments. The project name becomes your hostname (by default it matches the Git project name). The production branch is the branch used for the live site; for most projects that is main or master. Every other branch can produce preview deployments.
Production branch indicates the branch that Cloudflare Pages should use to deploy the production version of your site. For most projects, this is the main or master branch. All other branches that are not your production branch will be used for preview deployments.
You must have pushed at least one branch to the Git provider before you can select a production branch from the dropdown. When setup is complete, choose Save and Deploy; build logs show dependency install, build, and deploy to Cloudflare’s network. Finished deploys get a unique *.pages.dev URL.
Cloudflare Pages will automatically rebuild your project and deploy it on every new pushed commit.
Additionally, you will have access to preview deployments, which repeat the build-and-deploy process for pull requests.
On GitLab, you need Maintainer role or higher on the repository. Signing in with GitLab grants Pages access to repositories on that account (relevant on shared Cloudflare accounts).
If you scaffold with C3 CLI, answer no to terminal deploy when you plan to connect Git later—deploying first via Direct Upload blocks converting that project to Git integration.
Select no to the prompt, “Do you want to deploy your application?”. This is important — if you select yes and deploy your application from your terminal (Direct Upload), then it will not be possible to connect this Pages project to a git repository later on.
Build configuration: build command, output directory and root path
Section titled “Build configuration: build command, output directory and root path”Build configuration tells Pages how to build and where static assets land after the build.
You may tell Cloudflare Pages how your site needs to be built as well as where its output files will be located.
What the build command and build directory mean
Section titled “What the build command and build directory mean”The build command comes from your framework (for example Gatsby uses gatsby build). With no framework and no compile step, leave the build command empty. Pages treats the command’s exit code as success or failure: any non-zero code fails the build; exit code 0 succeeds and uploads assets even if errors were written to standard error.
The build directory (build output directory) is where the build command writes files Pages will serve. Names vary by tool (public, dist, _site, and others).
The root directory is where the site’s source lives in the repo. If unset, Pages uses the repository root. Set Root directory (advanced) > Path for monorepos with multiple apps in one repository.
The root directory is where your site’s content lives. If not specified, Cloudflare assumes that your linked git repository is the root directory. The root directory needs to be specified in cases like monorepos, where there may be multiple projects in one repository.
For sites that are already static files in Git with no build step, deploy anything recommends exit 0 as the build command when you still want features such as Pages Functions, and you set the output directory to wherever your files live.
If you are not using a preset and do not need to build your site, use exit 0 as your Build command. Cloudflare recommends using exit 0 as your Build command to access features such as Pages Functions.
Framework presets: default build command and output folder
Section titled “Framework presets: default build command and output folder”During project creation, Framework preset fills default build command and directory. Cloudflare maintains a table of common values in Build configuration. Examples:
| Framework / tool | Build command | Build directory |
|---|---|---|
| Astro | npx astro build |
dist |
| React (Vite) | npx vite build |
dist |
| Next.js (Static HTML Export) | npx next build |
out |
| SvelteKit | npx vite build |
.svelte-kit/cloudflare |
| Hugo | hugo |
public |
| Jekyll | jekyll build |
_site |
| Angular | npx ng build |
dist/cloudflare (sometimes dist/cloudflare/browser) |
| Blazor | ./build.sh (custom) |
output/wwwroot |
Some guides need extra flags or scripts—for example Hugo may use hugo -b $CF_PAGES_URL so baseURL matches the Pages URL, and Blazor uses a build.sh that installs .NET and publishes to output.
Per-framework walkthroughs (React, Vue, Nuxt, and others) repeat the same dashboard flow with preset-specific values; see the framework guides index via any linked guide such as Deploy an Astro site.
Production branch control and preview branch settings
Section titled “Production branch control and preview branch settings”Pages defaults production to the branch you first pushed. Change it under Settings > Builds & deployments (or Settings > Builds > Branch control for GitHub/GitLab integration docs).
Pages will default to setting your production environment to the branch you first push, but you can set your production to another branch if you choose.
You can enable or disable automatic deploys on the production branch (Enable automatic production branch deployments). Save settings for changes to apply.
For preview branches, branch build controls and GitHub integration let you include or exclude branches from automatic preview builds via Custom branches.
Direct Upload projects do not get production branch controls in the dashboard; update production_branch with the Pages API instead (see Direct Upload and branch build controls).
Direct Upload: deploy prebuilt assets without Git builds
Section titled “Direct Upload: deploy prebuilt assets without Git builds”Choose Direct Upload when you build elsewhere (local machine, CI) or upload a ZIP of static files (for example WordPress via Simply Static).
Direct Upload enables you to upload your prebuilt assets to Pages and deploy them to the Cloudflare global network. You should choose Direct Upload over Git integration if you want to integrate your own build platform or upload from your local computer.
With Wrangler, create a project and deploy the output folder:
npx wrangler pages project createnpx wrangler pages deploy <BUILD_OUTPUT_DIRECTORY>Preview uploads use --branch=<BRANCH_NAME>; branch aliases appear at <BRANCH_NAME>.<PROJECT_NAME>.pages.dev. The dashboard Drag and drop your files flow is described in the same Direct Upload guide.
Use Direct Upload with continuous integration shows GitHub Actions, CircleCI, or Travis CI running your build, then wrangler pages deploy with CLOUDFLARE_ACCOUNT_ID and CLOUDFLARE_API_TOKEN.
Deploy Hooks can trigger a new Git-connected deploy when external CMS data changes (example: Sanity webhook to a hook URL in Pages settings).
Environment variables and runtime versions during build
Section titled “Environment variables and runtime versions during build”Set variables under Settings > Environment variables (also available at first project setup in Git integration). Changes apply on the next deployment.
Common cases from the cluster:
- Private npm packages:
NPM_TOKENon Production and Preview, or scoped.npmrcwith tokens in env vars—see Install private packages. - Jekyll / Ruby:
RUBY_VERSION(for example3.1.3) in the Jekyll guide; migrating from GitHub Pages may need aGemfilewithgithub-pagesper Migrating a Jekyll-based site from GitHub Pages. - Python docs:
PYTHON_VERSION(for example3.7) for MkDocs, Pelican, Sphinx. - Hugo: default build may use an older Hugo; set
HUGO_VERSIONper Known issues. - Node: default Node in the build environment may be old; see Build configuration and framework guides (for example Hexo) for version variables.
- Zola: optional
ZOLA_VERSION; preview builds may need a dynamicbase_urlusingCF_PAGES_URL—see Deploy a Zola site.
For different npm scripts per branch, Set build commands per branch uses CF_PAGES_BRANCH in a wrapper script and sets the dashboard build command to bash build.sh.
Moving from another host: reuse build command and publish directory
Section titled “Moving from another host: reuse build command and publish directory”Migration guides share one pattern: read the old platform’s build command and output/publish directory, then create a Pages Git project with those values.
| Source | Where to read settings | Pages doc |
|---|---|---|
| Netlify | Build & deploy → Build command, Publish directory | Migrating from Netlify to Pages |
| Vercel | Settings → Build Command, Output Directory | Migrating from Vercel to Pages |
| Firebase Hosting | public in firebase.json; infer build command |
Migrating from Firebase |
Platform-specific serverless features may not map one-to-one (for example Vercel serverless functions vs Pages Functions). Known issues notes Netlify Forms are not supported; Pages Functions are the suggested alternative.
Migration guides also cover Workers Sites and other paths. Cloudflare’s docs note that Workers is the broader application platform; new projects may start on Workers instead of Pages—see Migration guides and Workers migration guides.
Common mistakes when configuring builds and deployment
Section titled “Common mistakes when configuring builds and deployment”- Wrong output directory — build succeeds but the site 404s or is empty; match the framework’s real output path (Angular’s
browsersubfolder, SvelteKit’s.svelte-kit/cloudflare, and so on). - Missing
index.htmlat the site root on*.pages.devwhen serving static files without a framework default—see Deploy anything. - Direct Upload first, then wanting Git — create a new Git-connected project instead.
- C3 or Wrangler deploy before Git connect — same constraint as Direct Upload.
- Production branch never pushed — dropdown stays empty until the branch exists on the remote.
- Env vars only on Production — preview builds fail on private npm or wrong Ruby/Python versions; set both environments where docs require it.
- Assuming
*.pages.devsubdomain is renameable — Known issues states you must delete and recreate the project to change it. - Hardcoded
base_urlon static generators — preview URLs break; useCF_PAGES_URLor branch-aware build commands (Zola, Hugo).
Jekyll sites that need /.well-known for Android Trusted Web Activity on GitHub Pages must include that folder in Jekyll output (include: [.well-known] in _config.yml) per Android concepts for web developers—relevant when the same Jekyll site is built on Pages with jekyll build.
How to check this on your site
Section titled “How to check this on your site”-
Open Workers & Pages in the Cloudflare dashboard, select your project, and confirm the latest deployment status and production URL match the commit you expect.
-
In Settings > Builds & deployments, verify Production branch, Build command, Build directory, and Root directory match your framework’s documented output (compare with Build configuration or your framework guide).
-
Open the production
*.pages.devURL (or custom domain) and confirm pages load; for SPAs, check client-side routes behave as described in your framework guide (for example Deploy a React site on SPA rendering). -
Push a non-production branch or open a pull request and confirm a preview deployment URL appears, as described in Git integration.
-
You can check automatically in Answerwell (our tool): https://answerwell.org/workspace
Report an error or ask a question
Section titled “Report an error or ask a question”If something on this page is wrong or unclear, email yimasynthetic@gmail.com with the page URL and the exact statement you are asking about so it can be corrected or explained.