DevOps / GitHub Actions Interview Questions
How do you use the actions/checkout action and what does it do?
actions/checkout clones your repository onto the runner so subsequent steps have access to your source code. Without it, the runner's working directory is empty — no source files, no scripts. It is almost always the first step in any CI job.
The simplest usage just checks out the default branch at the ref that triggered the workflow:
steps: - uses: actions/checkout@v4
Common configuration options via with::
ref:— Check out a specific branch, tag, or SHA. Useful when you need to build a release tag or compare against another branch.fetch-depth:— Number of commits to fetch. Defaults to1(shallow clone). Set to0for a full history (needed for tools likegit logor semantic-release that inspect commit history).token:— Override the defaultGITHUB_TOKENwith a PAT when you need to push commits back or access private submodules.submodules:— Set totrueor'recursive'to initialise Git submodules.
steps: - uses: actions/checkout@v4 with: fetch-depth: 0 # full history for changelog generation submodules: recursive # also clone submodules
The action authenticates using the workflow's GITHUB_TOKEN by default, so it works without any additional secret configuration for normal repository checkouts. For pull requests from forks it checks out a merge commit (the result of merging the fork's head into the base branch) rather than the fork's raw head commit, which prevents untrusted code from poisoning the checkout.
More Related questions...