While trying to make sense of the action actions/checkout@version
, I came across this answer in which the following was stated to explain what happens when the same action is executed:
The default steps being executed are:
The current repo in which the workflow is being triggered gets cloned.
Depending on the defined events such as a push or pull request:
For a push event, it runs the command below, where$GITHUB_REF
points to the latest commit on the specified branch for the push event in the workflow:
git fetch --depth 1 $GITHUB_REF
What I don't understand pertains to the reason the latest commit is fetched after the repository have just been cloned and thus is already up to date.
The first step mentioned in your quote is incorrect (Emphasis mine):
- The current repo in which the workflow is being triggered gets cloned.
Having looked at the code [GitHub] for the action here are the steps it performs to checkout the reference:
You can note here that the repository isn't actually cloned and rather than that a remote is configured on the newly initialized empty repository. Hence running fetch
is really needed since it doesn't yet actually have the commit.
Note: I've skipped some of the other steps that the code performs that aren't relevant to the question.