AWS
S3
Git
Deployment
Cloud Storage

Publish to S3 using Git?

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design

Introduction

Git does not publish to S3 by itself. What people usually mean is "use Git events or Git state to trigger a deployment to S3," often for static websites, build artifacts, or generated assets.

The practical workflow is: detect the desired Git revision, build the output if needed, and then upload the resulting files with the AWS CLI or SDK. Git provides the source-of-truth version, while S3 is the deployment target.

Use Git to Decide What to Publish

A common first step is identifying the revision you want to deploy:

bash
git rev-parse --short HEAD

You might use that commit hash in logs, release folders, or cache-busting paths. For example, a deployment script could upload build output to a versioned prefix.

Upload with the AWS CLI

For static files, the usual deployment primitive is aws s3 sync:

bash
aws s3 sync ./dist s3://my-site-bucket --delete

This uploads the contents of ./dist to the bucket and removes objects that no longer exist locally.

That is often all you need for a static site deployment after a Git-based build step.

Example Git-Aware Deployment Script

A small shell script might combine Git metadata with S3 publishing:

bash
1#!/usr/bin/env bash
2set -euo pipefail
3
4COMMIT=$(git rev-parse --short HEAD)
5echo "Deploying commit $COMMIT"
6
7npm run build
8aws s3 sync ./dist s3://my-site-bucket/releases/$COMMIT --delete

This is not Git publishing directly to S3. It is a Git-aware deployment script that uses the current revision as deployment metadata.

Use Git Hooks or CI, Not Manual Guesswork

If you want deployment to happen automatically, the clean place is usually CI rather than a local Git hook. For example:

  • push to main branch
  • CI checks out the commit
  • CI builds the project
  • CI runs aws s3 sync

That produces a repeatable deployment path and avoids hidden workstation-specific behavior.

Be Careful with --delete

The --delete flag is powerful and often correct for static sites, but it can also remove objects you did not intend to touch. Use it only when the local directory is truly the full desired state of the target prefix.

For safer rollout patterns, publish to a versioned prefix first and switch traffic later instead of overwriting the live path immediately.

Separate Build Output from Source Control State

A good deployment flow distinguishes clearly between the Git-tracked source and the generated files that will actually be uploaded. That separation makes it easier to reproduce deployments and easier to understand what S3 is supposed to contain.

It also reduces the chance of accidentally publishing source files that were never meant to be deployed directly.

That keeps the S3 target aligned with the artifact you actually intended to release.

Common Pitfalls

  • Thinking Git itself can publish files to S3 without an external script or CI step.
  • Deploying directly from an unbuilt working tree instead of from a build output directory.
  • Using aws s3 sync --delete against the wrong bucket or prefix.
  • Running deployments from local machines when CI would provide better reproducibility.
  • Ignoring the Git revision and losing traceability between deployed assets and source commits.

Summary

  • Git is the source-of-truth for versioning, not the actual S3 publisher.
  • Use Git state to decide what revision is being deployed.
  • Use aws s3 sync or similar tooling to publish files to S3.
  • Prefer CI pipelines over ad hoc local deployment flows.
  • Keep Git revision metadata in the deployment process so releases stay traceable.

Related reading
Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design

All Rights Reserved.