Hello 🙂 Lately I’ve discovered that actions/checkout@v4 in Github doesn’t behave as I thought. I have a very simple pipeline with first step defined like this:
on:
pull_request:
branches:
- 'main'
jobs:
run-tests:
runs-on: 'ubuntu-latest'
defaults:
run:
working-directory: ./
steps:
- name: Checkout
uses: actions/checkout@v4
- runing tests etc etd
My idea was that git just checkouts on my branch. Turns out it takes my commit and merges them on main. I’ve started looking at exact command that are run:
1. git init /home/runner/work/my-repo/my-repo
2. git remote add origin https://github.com/MyOrg/my-repo
3. git config --local gc.auto 0
4 ...some commands to setup up auth...
git config --local --name-only --get-regexp core.sshCommand
git submodule foreach --recursive sh -c "git config --local --name-only --get-regexp 'core.sshCommand' && git config --local --unset-all 'core.sshCommand' || :"
git config --local --name-only --get-regexp http.https://github.com/.extraheader
git submodule foreach --recursive sh -c "git config --local --name-only --get-regexp 'http.https://github.com/.extraheader' && git config --local --unset-all 'http.https://github.com/.extraheader'
5. Fetching
git -c protocol.version=2 fetch --no-tags --prune --no-recurse-submodules --depth=1 origin +branchRemoteRef:refs/remotes/pull/69420/merge
6. Some config
git sparse-checkout disable
git config --local --unset-all extensions.worktreeConfig
7. Checkout
git checkout --progress --force refs/remotes/pull/69420/merge
And once 7. git checkout
is run I can see this message:
HEAD is now at #someCommitHash Merge branchRemoteRef into #latestMainCommit
.
So I don’t think anything important (for my case) happens in other steps than 5 and 7 but I just pasted everything to be clear. I feel like I’m missing some git knowledge. Why, when git checkout
is run, it merges into main? How does it know what is the latest commit on main? How does it even know that it should take from main (does it just use default branch?)? I’ve read documentation and tried to search online but couldn’t find an answer. This post /a/70274029 confirms that this magic merging happens but I would like to understand why does it happen…