GitHub Actions Tutorial — Checkout & Setup
Checkout & Setup Actions
Two actions appear in virtually every workflow: actions/checkout (to get your code) and actions/setup-* (to install a language runtime). Understanding their options is essential.
actions/checkout
By default, actions/checkout@v4 clones your repository at the commit that triggered the workflow.
Basic Usage
steps:
- uses: actions/checkout@v4
- run: ls -la # your repo files are here
Common Options
steps:
- uses: actions/checkout@v4
with:
# Check out a specific branch or tag
ref: 'develop'
# Check out full history (for changelogs, git blame)
fetch-depth: 0 # 0 = full history, default is 1 (shallow)
# Check out submodules
submodules: true # or 'recursive'
# Check out a different repository
repository: 'owner/other-repo'
token: ${{ secrets.PAT }}
# Check out to a specific path
path: 'my-repo'
Key Options Reference
| Option | Default | Purpose |
|---|---|---|
ref |
Trigger ref | Branch, tag, or SHA to checkout |
fetch-depth |
1 |
Git history depth (0 = full) |
submodules |
false |
Initialize submodules |
token |
github.token |
Auth token (needed for private repos) |
path |
. |
Directory to clone into |
clean |
true |
Clean before checkout |
When to Use fetch-depth: 0
| Use Case | fetch-depth |
|---|---|
| Standard CI (build/test) | 1 (default, fastest) |
| Generate changelog | 0 (needs full history) |
| Git blame / git log | 0 |
| Semantic versioning from tags | 0 |
| Count commits since last tag | 0 |
actions/setup-node
Install a specific Node.js version:
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- run: node --version # v20.x.x
Options
steps:
- uses: actions/setup-node@v4
with:
node-version: '20.x' # major version
node-version-file: '.nvmrc' # read from file
cache: 'npm' # cache npm dependencies
registry-url: 'https://npm.pkg.github.com' # for publishing
actions/setup-python
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.12'
- run: python --version # Python 3.12.x
Options
steps:
- uses: actions/setup-python@v5
with:
python-version: '3.12'
cache: 'pip' # cache pip dependencies
cache-dependency-path: 'requirements.txt'
actions/setup-java
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
distribution: 'temurin' # Eclipse Temurin (recommended)
java-version: '21'
cache: 'maven'
- run: java --version
Java Distributions
| Distribution | Value |
|---|---|
| Eclipse Temurin | temurin |
| Azul Zulu | zulu |
| Amazon Corretto | corretto |
| Microsoft Build | microsoft |
| Oracle JDK | oracle |
actions/setup-go
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: '1.22'
cache: true
- run: go version
actions/setup-dotnet
steps:
- uses: actions/checkout@v4
- uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.0.x'
- run: dotnet --version
Pattern — Setup with Caching
Every setup-* action supports built-in dependency caching:
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
cache: 'npm' # automatically caches ~/.npm
- run: npm ci # fast — uses cached dependencies
- run: npm test
Caching dramatically speeds up workflows by skipping redundant dependency downloads. We cover this in depth in Artifacts & Caching.
Common Mistakes
| Mistake | Fix |
|---|---|
Forgot actions/checkout |
Without it, your repo files aren’t on the runner |
Shallow clone breaks git log |
Use fetch-depth: 0 for full history |
| Wrong Node.js version | Check .nvmrc or package.json engines field |
| Cache not working | Ensure the cache: input matches your package manager |
Quick Reference
| Action | Purpose | Key Input |
|---|---|---|
actions/checkout@v4 |
Clone repository | ref, fetch-depth |
actions/setup-node@v4 |
Install Node.js | node-version, cache: npm |
actions/setup-python@v5 |
Install Python | python-version, cache: pip |
actions/setup-java@v4 |
Install Java | distribution, java-version |
actions/setup-go@v5 |
Install Go | go-version, cache: true |
actions/setup-dotnet@v4 |
Install .NET | dotnet-version |
← Previous: Using Actions
Next: Action Inputs & Outputs →