Search code examples
githubgitlabcontinuous-integrationgithub-actionsaction

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


Solution

  • 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.