GitHub Actions Basics
GitHub Actions runs commands for you on GitHub’s computers whenever something happens in the repository — for example, testing every push.
On this page · 5 min · Advanced
On this page
- Learning objectives
- Explanation
- Step-by-step screens
- Code example
- Step by step
- Real-world use
- Common mistakes
- Best practices
- Remember this
- Practice exercise
- Mini quiz
- Related topics
- My notes
- Reading time
- 5 min
- Difficulty
- Advanced
- Updated
- Nov 25, 2026
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#
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
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#
- name appears in the Actions tab.
- on lists the events that start it.
- checkout downloads your code onto the runner.
- setup-node installs Node 22 with npm caching.
- 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#
Workflows must be in .github/workflows/ (with the dot) or GitHub ignores them.
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
on: [push, pull_request]
Mini quiz#
Where do workflow files live?
Want more? Practise all Git & GitHub MCQs · Git & GitHub interview questions
My notes#
Saved in this browser.