Git & GitHub · Publish & Automate

GitHub Actions Basics

GitHub Actions runs commands for you on GitHub’s computers whenever something happens in the repository — for example, testing every push.

Advanced 5 min Lesson 18 of 19Shows Git 2.47 and GitHub.com as of 2026. GitHub changes its layout from time to time; button names stay the same.
Before you start:Commit, Push and Pull
0/19 in Git & GitHub
On this page · 5 min · Advanced

Learning objectives#

  • Explain workflows, jobs and steps
  • Add a starter workflow
  • Read a run and its log
  • Add a status badge to the README

Explanation#

A workflow is a YAML file in .github/workflows/. on: says when it runs (push, pull_request); jobs: run on a fresh virtual machine (runs-on: ubuntu-latest); steps: are commands (run:) or ready-made actions (uses:).

The Actions tab suggests starter workflows for your language. Click Configure, review the file and commit it — the first run starts immediately.

Each run shows its jobs and steps with a green ✓ or red ✗. Click a failed step to read the log; the error is usually in the last lines.

Copy the status badge (… → Create status badge) into README.md so visitors see whether the build passes.

Step-by-step screens#

Drawings of github.com, the Git installer, VS Code and a terminal. GitHub changes its layout from time to time; the button names stay the same. The red numbers match the numbered actions under each picture; names on your computer will differ.

Loading pictures…

Code example: Check a Node.js project on every push and PR#

YAML.github/workflows/ci.yml Illustrative
name: ci
on: [push, pull_request]


jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: 22
          cache: npm
      - run: npm ci
      - run: npm test
Expected output
Every push shows a yellow dot (running), then a green ✓ or red ✗ next to the commit on GitHub. Pull requests show the check before merging.

This example is illustrative. Copy or download it and run it in your own environment; the expected output is shown above.

Step-by-step explanation#

  1. name appears in the Actions tab.
  2. on lists the events that start it.
  3. checkout downloads your code onto the runner.
  4. setup-node installs Node 22 with npm caching.
  5. npm ci and npm test install and test.

Real-world use case#

A student’s project shows a green “ci passing” badge; with branch protection, broken code can no longer be merged into main.

Common mistakes#

Wrong folder

Workflows must be in .github/workflows/ (with the dot) or GitHub ignores them.

Tabs in YAML

YAML needs spaces for indentation. A single tab makes the file invalid.

Best practices#

  • Start from a starter workflow
  • Run on pull_request too
  • Cache dependencies
  • Require the check in branch protection

Remember this#

.github/workflows/*.yml

on → jobs → steps.

Red ✗? read the last log lines.

Practice exercise#

Your task: Write the on: line that runs a workflow for pushes and pull requests.

Show solution
YAML Illustrative
on: [push, pull_request]

Mini quiz#

GitHub Actions Basics quizMultiple choice Question 1 of 1

Where do workflow files live?

Score so far: 0/0

Want more? Practise all Git & GitHub MCQs · Git & GitHub interview questions

My notes#

Saved in this browser.

Progress is saved in this browser. Sign in to sync.