Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the purpose of actions/checkout@v3, when the repository is already checked out on job start?

I've previously used GitLab, where I didn't checkout the repository explicitly. Instead it was done automatically by the pipeline.

Thus, I was surprised that almost all GitHub Actions workflows use e.g. actions/checkout@v3.

But what's the purpose besides checking out a different repository?

As seen from the below screenshot, my repository is already checked out, when the job starts:

enter image description here

like image 308
Shuzheng Avatar asked Sep 10 '25 23:09

Shuzheng


2 Answers

Without the checkout action GitHub wont clone your repository and you will get an empty folder. You can check this with a very basic action.yml

name: My Workflow
on: push
jobs:
  myjob:
    runs-on: ubuntu-latest
    steps:
      - name: just a simple ls command
        runs: ls -la

Here is a video showing this and explaining it a bit more: https://www.youtube.com/watch?v=-61_kIikldQ

I am not sure how its showing the files in your case. Maybe you got a stale docker environment with files from previous runs because of a bug. I just tested it and I don't have any files without running the checkout first.

like image 183
mustafa candan Avatar answered Sep 13 '25 18:09

mustafa candan


By default, this action will check-out to the SHA for that workflow’s event (such as push and pull_request). Otherwise, uses the default branch (usually main or master in a standard repository).

You should use the checkout action any time your workflow will use the repository's code.

https://docs.github.com/en/actions/learn-github-actions/understanding-github-actions#understanding-the-workflow-file

This action checks-out your repository under $GITHUB_WORKSPACE, so your workflow can access it.

https://github.com/actions/checkout

So you can specify the repo, branch, path, submodule and so on to which you can checkout. Also you can use fetch-depth to include git history as necessary.

Also note, that it's cloning the files to $GITHUB_WORKSPACE.

like image 21
Robin Thomas Avatar answered Sep 13 '25 17:09

Robin Thomas