๐Ÿ™

How Do GitHub Webhooks Work?

git push โ†’ HTTP POST โ†’ CI/CD Trigger

GitHub Webhooks work by registering a URL in Repository Settings > Webhooks. When an event occurs, GitHub sends an HTTP POST with a JSON payload to that URL. The X-Hub-Signature-256 header includes an HMAC signature to verify the request authenticity. The receiving server must return 200 OK within 10 seconds, and GitHub automatically retries on failure.

Architecture Diagram

Setup
๐Ÿ‘ค
Repository Owner
Settings → Webhooks → Add
๐Ÿ™
GitHub
Save URL + Secret
When Event Occurs
๐Ÿ‘จโ€๐Ÿ’ป
Developer
git push
๐Ÿ™
GitHub
push event detected
HTTP POST
X-Hub-Signature-256
X-GitHub-Event: push
๐Ÿ–ฅ๏ธ
My Server
Verify signature CI/CD trigger
Signature Verification (security required!):
expected = HMAC-SHA256(secret, body)
actual = request.headers["X-Hub-Signature-256"]
secure_compare(expected, actual) # true → valid
Notes
  • Must return 200 OK within 10 seconds (heavy processing should be done in background)
  • GitHub auto-retries on failure (up to 3 times)
  • Delivery logs available in Settings โ†’ Webhooks
  • ngrok needed for local development (no public URL)

How It Works

1

Register Webhook URL + Secret in Repository Settings

2

Developer runs git push (or creates PR, Issue, etc.)

3

GitHub sends HTTP POST to registered URL (JSON payload)

4

HMAC-SHA256 signature included via X-Hub-Signature-256 header

5

Receiving server verifies signature then processes event (CI/CD trigger, etc.)

6

Server returns 200 OK (within 10s, GitHub retries on failure)

Pros

  • Very simple setup
  • Fine-grained event type selection
  • Automatic retry on failure
  • Delivery logs viewable in GitHub UI

Cons

  • Public URL required (ngrok needed for local development)
  • 10-second timeout (heavy processing must be async)
  • Signature verification implementation needed
  • No event ordering guarantee

Use Cases

CI/CD auto builds (Jenkins, GitHub Actions) Slack/Discord notifications Automatic deployment triggers Code review bots