GitHub Actions cheat sheet

GitHub Actions automates CI/CD directly in GitHub repositories.

On this page

Table of contents

Use this page for fast recall. Use Full documentation when you want the complete end-to-end path.

Quick workflow

A simple 5-step flow you can follow when using GitHub Actions in real work.

1) Setup

Install/run the tool and confirm version. Create a minimal config.

2) Small change

Do one small action end-to-end to prove the workflow.

3) Validate

Check output, logs, and status. Catch mistakes early.

4) Automate

Convert it into a repeatable script or pipeline step.

5) Productionize

Add safety: secrets, rollback, observability, and docs.

Workflows you will actually reuse

These are practical sequences you can copy into your own checklist or runbook.

Deploy on push to main (safe)

Goal: Automate deployment while keeping secrets secure and rollbacks possible.

- Use GitHub Secrets for SSH keys and environment vars.

- Run `docker compose up --build -d` on your server via SSH action.

- Log outputs and fail the workflow if deployment fails.

- Add a simple health check step after deploy.

- Add manual approval for production if you need a gate.

Key Concepts

- Workflows

- Jobs

- Runners

Learning path (high-level):

- Build CI workflow

- Add tests

- Add deployment gates

Quick Start

Create workflow folder

Command

mkdir -p .github/workflows

Add CI file

Command

touch .github/workflows/ci.yml

Push to trigger

Command

git push origin main

Common Commands

Short descriptions and practical intent. Search, filter, copy, and reuse.

Showing 8

CLI
gh workflow list

List workflows in the repository.

CLI
gh run list

List recent workflow runs.

CLI
gh run view <id>

Open details for a workflow run.

CLI
gh run watch <id>

Watch run progress in terminal.

CLI
gh run rerun <id>

Rerun a failed workflow run.

Secrets
gh secret set MY_SECRET

Set a repository secret from terminal.

Secrets
gh variable set MY_VAR

Set a repository variable.

Local
act

Run GitHub Actions locally (if installed).

Copyable snippets

Small blocks you can drop into your terminal, config, or runbook.

Minimal deploy via SSH (example)

Use secrets for host/user/key and keep server permissions tight.

yaml

name: Deploy
on:
  push:
    branches: [main]

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Deploy on server
        uses: appleboy/ssh-action@v1.2.0
        with:
          host: ${{ secrets.AZURE_HOST }}
          username: ${{ secrets.AZURE_USER }}
          key: ${{ secrets.AZURE_SSH_PRIVATE_KEY }}
          script: |
            cd /home/azureuser/DevOpsLabX-New
            git pull origin main
            docker compose up --build -d

Troubleshooting checklist

When things break, follow this order to stay calm and move fast.

- If checkout/pull fails: verify repo permissions and authentication for private repos.

- If secrets are missing: ensure they are defined in repo settings and referenced correctly.

- If deploy is slow: avoid rebuilding unchanged layers; use a registry and pull images.

Pitfalls

The common mistakes that slow people down when using GitHub Actions.

- Copy-pasting commands without understanding inputs/outputs and side effects.

- Not documenting defaults (ports, paths, credentials) and then getting stuck in prod.

- Skipping logs and metrics when troubleshooting; always collect evidence first.

Mini lab (practice)

Do these tasks in order. You will feel the tool instead of just reading about it.

- Install or run the tool locally (or in Docker) and verify it works with a hello-world action.

- Create a minimal config and run the most common command 3 times (with a small change each time).

- Break something on purpose and document how you debugged it in your Notes.

Interview prompts

Use these to test if you truly understand the basics (and can explain them clearly).

- Explain the tool’s role in a real CI/CD pipeline from commit to production.

- Describe the most common failure you’ve seen with this tool and how you fixed it.

- What would you monitor/alert on for this tool in production?

Official Docs

https://docs.github.com/actions