checkout: checkout@v2 not getting recent commits
Assume a Github action with two Jobs - job1 & job2
In job1: Use checkout action to checkout the repo, update any file in the repo, commit and push the changes.
In job2:
Again use checkout action. The repo doesn’t contain the commit made in job1.
Here is a replicable sample:
jobs:
update-version:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- run: |
// update file1.txt
git add file1.txt
git config --local user.email "github-actions@users.noreply.github.com"
git config --local user.name "github-actions"
git commit -m "updated file1"
git push
deploy:
needs: update-version
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: cat publish file
run: |
# the changes made in job1 are not reflected here
cat file1.txt
About this issue
- Original URL
- State: open
- Created 3 years ago
- Reactions: 54
- Comments: 25
Commits related to this issue
- feat: try bug fix for commit - https://github.com/actions/checkout/issues/439 refs: 7851 — committed to 2pisoftware/cmfive-core by twje 3 years ago
- Specify ref in GHActions checkout action to get latest (see: https://github.com/actions/checkout/issues/439) — committed to Shopify/yjit-metrics by noahgibbs 3 years ago
- chore(github action workflow): define branch for checkout to make sure intermediate commits are included without defining branch, the second checkout would skip previous automatic commits see https:/... — committed to secvisogram/csaf-cms-backend by deleted user 2 years ago
- chore(github action workflow): define branch for checkout to make sure intermediate commits are included without defining branch, the second checkout would skip previous automatic commits see https:/... — committed to secvisogram/csaf-cms-backend by deleted user 2 years ago
- :green_heart: Fix CI build that was related to this issue https://github.com/actions/checkout/issues/439 — committed to iqfareez/astros-api by iqfareez 2 years ago
- chore(workflow): add input to checkout Reference: https://github.com/actions/checkout/issues/439 https://github.com/octorelease/octorelease/issues/34 — committed to marcolovazzano/semantic-release by marcolovazzano 2 years ago
- Fetch full repository on GitHub Actions workflow Fetching with the default fetch-depth of 1 led to a strange bug where the commit fetched would be different from the one that triggered the build, unl... — committed to punchagan/sandmark-nightly by punchagan 2 years ago
- Fetch full repository on GitHub Actions workflow Fetching with the default fetch-depth of 1 led to a strange bug where the commit fetched would be different from the one that triggered the build, unl... — committed to punchagan/sandmark-nightly by punchagan 2 years ago
- Fetch full repository on GitHub Actions workflow Fetching with the default fetch-depth of 1 led to a strange bug where the commit fetched would be different from the one that triggered the build, unl... — committed to punchagan/sandmark-nightly by punchagan 2 years ago
- Fetch full repository on GitHub Actions workflow Fetching with the default fetch-depth of 1 led to a strange bug where the commit fetched would be different from the one that triggered the build, unl... — committed to punchagan/sandmark-nightly by punchagan 2 years ago
- [images] Fix issue with checkouting the repo See https://github.com/actions/checkout/issues/439 — committed to HITB-CyberWeek/hitbsecconf-ctf-2022 by andgein 2 years ago
- Force Action to grab most recent commit Based on information found on https://github.com/actions/checkout/issues/439 — committed to osg-htc/osg-portal by CannonLock 2 years ago
- When transforming to views, always use master branch data (#346) Should close #219 actions/checkout#439 (comment) encourages setting the ref explicitly to always pull the latest data from the ref. ... — committed to nvaccess/addon-datastore by seanbudd a year ago
- Specify ref in build workflow So… when the scrape workflow triggers the build workflow, the build workflow doesn't check out the latest commit. This appears to be an issue because it inherits the SHA... — committed to jgarber623/nasa-apod by jgarber623 a year ago
- Fix https://github.com/actions/checkout/issues/439 — committed to hathagat/nginx by hathagat 10 months ago
- Update import.yaml always checkout latest version of the data repo see https://github.com/actions/checkout and https://github.com/actions/checkout/issues/439 — committed to research-software-ecosystem/content by hmenager 9 months ago
- Update import.yaml solve the issue of successive import tasks in the repo not working because the latest repo commit is not checked out by the next task. As described in https://github.com/actions/ch... — committed to research-software-ecosystem/content by hmenager 8 months ago
- Fix fetching of newly created PR in awesome-template-sync Refs: https://github.com/actions/checkout/issues/439 — committed to kdeldycke/workflows by kdeldycke 4 months ago
- Workaround actions checkout not pulling latest version See https://github.com/actions/checkout/issues/439 — committed to corentin-regent/rate-control by corentin-regent 3 months ago
- Workaround actions checkout not pulling latest version See https://github.com/actions/checkout/issues/439 — committed to corentin-regent/rate-control by corentin-regent 3 months ago
I ran into the same problem and came across this issue. But could figure out a solution within the documentation.
This means by default the commit where the workflow was triggered will be taken. You can specify the master branch with
ref: 'master'
As @sebastian-muthwill mentions, you can use the
ref
attribute to point to a specific branch. This way subsequent jobs always pull the latest code from that branch, and not from the revision that started the workflow.@mugbug I think
fetch-depth: 0
is your friend.Here’s a full example that works for me when running multiple jobs that each generate a change-log file (i.e. modify the branch)
@adnan-kamili Does this solve your issue?
I don’t get any error, the checkout succeeds but it doesn’t get the latest commits. Seems to use some sort of cache. As a workaround I am doing the following:
IMO the best™ approach is the following:
By passing the commit hash of the pushed commit from the first job
update-changelog
to the second jobpublish
, we ensure that we check out exactly what we pushed before and not something that might have been pushed in between the job runs.This isn’t really an issue, but a topic surrounded by a bit of confusion in regards to how the action works. When we talk about push events to branches, by default, the action ensures that it exactly checks out the commit specified in the
github.sha
variable of thegithub
context. Because the value ofgithub.sha
doesn’t change over the lifetime of a workflow run, the action checks out the same commit across all jobs, whether you push something or not.By setting the
ref
parameter tomain
or${{ github.ref }}
, the behavior of the action changes and it will instead always pull the latest commit available. Runninggit pull
has effectively the same result. This will work fine in the majority of cases, but race conditions may occur:For anyone interested, you can read more about this topic on my blog (shameless plug).
The one thing I’m still curious about is people reporting different results between operating systems. I’ve had a bit of fun analyzing this, so I created a repository that runs daily tests with the following scenarios:
git pull
ref: ${{ github.ref }}
I run these tests on all the runner images available (
ubuntu-22.04
,ubuntu-20.04
,macos-12
,macos-11
,windows-2022
,windows-2019
), but so far the everything returns the expected results. 🤷 I thought that these discrepancies might stem from the different Git implementations used within the runner images. I’ll keep an eye on the results, maybe something turns up in the future.For anyone interested, I use Hugo to automatically publish the results here: https://commit-and-checkout-actions-workflow.schnerring.net/. Turning this into unit tests would also be pretty straightforward.
Having the same issue with actions/checkout@v3. The checkout function is pulling the most recent version of the repository for windows and macos, but not for ubuntu-latest.
It is pulling an older version of the repository for the ubuntu-latest runner and because of this my linux tests are failing. Tried many of the suggestions above, none have worked to fix this issue.
fetch-depth: 0
worked for me,ref:
is irrelevant in my case.To add to @restfulhead’s answer,
fetch-depth: 0
is not necessary. This example always checks out the latest commit of the branch that triggered the workflow.ref
doesn’t work for me 😦I confirm it is still there.
What the hell, I was thinking I was popping crazy pills, how is this even an issue.
I was having this same issue with checkout@v4, thought I was taking wacky pills, so I am very thankful for this thread! It feels great knowing that I am not alone in this issue.
In the end, the
fetch-depth
option wasn’t necessary, but adding theref: main
to my checkout step did the trick.So, for any of you checkout@v4 folks this is what worked for me:
Thanks, This worked for me!
I had a similar issue while trying to use
standard-version
to generate the changelog with previous commits. The problem was that it wasn’t fetching the commit history and only the last commit was available. I was able to solve this by running this command, which forces the commit history to be fetched:Running into the same issue. We should be able to do a checkout again without needing to specific the ref in dispatch workflow.
Dispatch Workflow starts off with checking out branch (2)
Step 4 seems to be pulling an old branch git sha.
Maybe this is normal behavior? According to this https://docs.github.com/en/actions/reference/events-that-trigger-workflows#manual-events
If I check out branch (2) it will use the last github_ref. So even if I update the branch (2) and run step 4, it will still pull the older branch. Can someone help confirm?
I ran into the same issue. I have 2 jobs: Job-1: actions/checkout@v2, modify a file, commit the file, push the file
Job2: actions/checkout@v2
It doesn’t error out but it does log below which shows the last commit pushed within Job-1 is not there.
As a workaround, I had to do
- run: git pull --no-rebase
with Job-2 checkout (similar to what @adnan-kamili mentioned above)