I am using GitHub Actions for CI/CD and using actions/checkout@v4
to check out current branch code in the action job. During development, I create a feature branch from develop
branch then create a PR to merge to develop
branch.
In my build job, I need to compare the changes between feature branch and develop branch, so I need to fetch develop branch as shown in below workflow file:
steps:
- uses: actions/checkout@v4
- name: Fetch base branch
run: |
git fetch origin ${{ github.base_ref }}
...
The interesting part is that the actions/checkout@v4
took 3 seconds to finish but the git fetch origin develop
command took 30 seconds to finish. The two branches are basically similar with only a few changed files. I wonder why it has a lot different when checking out the code. Does GitHub Actions do some optimisation on current branch?
The checkout action uses git fetch --depth=1
by default.