Netlify and Gatsby are a dream team for shipping static sites, but the real magic isn’t just that they can deploy automatically; it’s how they achieve it with almost zero manual intervention after the initial setup.

Let’s see this in action. Imagine you have a Gatsby site hosted on GitHub. You’ve connected your GitHub repository to Netlify, and Netlify is set to build your Gatsby project on every push to your main branch.

Here’s a peek at what a successful deploy looks like in Netlify’s UI:

Deploy: a1b2c3d4e5f678901234567890abcdef - Deployed
Build:
  - Netlify build image: `ubuntu-22.04`
  - Build command: `npm run build`
  - Publish directory: `public`

When you push a change, Netlify spins up a fresh build environment, runs npm run build (which Gatsby uses to generate your static files), and then deploys the contents of the public directory to its global CDN. That’s it. No servers to manage, no manual uploads.

The core problem this solves is the friction between development and deployment. Traditionally, you’d build your site locally, then use rsync or an FTP client to upload files to a web server. This process is error-prone and time-consuming. Netlify and Gatsby automate this by treating your website as code that’s version-controlled and built on demand.

Under the hood, Netlify acts as a CI/CD (Continuous Integration/Continuous Deployment) platform specifically optimized for static sites. When you connect a Git repository, Netlify monitors it for changes. Upon detecting a push to a designated branch (like main), it pulls the latest code, installs dependencies (using npm install or yarn install), runs your build command (configured in netlify.toml or the Netlify UI), and then distributes the resulting static assets (HTML, CSS, JS, images) across its worldwide network of servers. Gatsby, in this setup, is the engine that generates those static assets from your React components and data.

The key levers you control are:

  • Build Command: This is the script Netlify runs to build your site. For Gatsby, it’s almost always npm run build or yarn build. You can customize this in your netlify.toml file:
    [build]
      command = "npm run build"
      publish = "public"
    
  • Publish Directory: This tells Netlify where to find the final static files after the build command finishes. Gatsby’s default output directory is public.
  • Environment Variables: You can set environment variables in Netlify’s UI (e.g., for API keys used during the build process) that are injected into the build environment.
  • Branch Deploys: Netlify can automatically deploy branches other than main, which is fantastic for previewing changes before merging.
  • Custom Domains & HTTPS: Netlify handles DNS configuration and automatically provisions SSL certificates for your custom domain.

Netlify’s build process is designed to be fast and efficient, leveraging caching to speed up subsequent builds. It analyzes your package.json to determine dependencies and uses a cached node_modules directory where possible. The build itself happens within isolated containers, ensuring a consistent environment every time, regardless of your local machine’s setup. This reproducibility is crucial for reliable deployments.

The "magic" of Netlify’s CDN is in its edge network. When a user requests your site, Netlify serves the content from the server geographically closest to them, minimizing latency. This isn’t just about speed; it’s also about resilience. If one server has an issue, traffic is automatically rerouted to another.

What most people don’t realize is that Netlify’s build cache is specific to your site and the exact build command and publish directory. If you change your build command in netlify.toml but forget to clear the cache, Netlify might still try to use the old build configuration, leading to confusing errors or incorrect deployments. The cache is a powerful tool for speed, but it requires understanding its boundaries.

The next logical step after mastering automatic deployments is understanding how to implement features like serverless functions directly within Netlify for dynamic backend logic.

Want structured learning?

Take the full Netlify course →