{"id":16877177,"url":"https://github.com/rmacklin/fetch-through-merge-base","last_synced_at":"2025-10-07T14:45:36.819Z","repository":{"id":146967113,"uuid":"332074923","full_name":"rmacklin/fetch-through-merge-base","owner":"rmacklin","description":"A GitHub Action for fetching PR commits through the merge-base","archived":false,"fork":false,"pushed_at":"2021-01-25T03:36:27.000Z","size":5,"stargazers_count":12,"open_issues_count":1,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-25T07:51:14.839Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rmacklin.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-01-22T22:16:12.000Z","updated_at":"2024-10-28T00:13:16.000Z","dependencies_parsed_at":"2023-04-15T19:18:11.442Z","dependency_job_id":null,"html_url":"https://github.com/rmacklin/fetch-through-merge-base","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rmacklin%2Ffetch-through-merge-base","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rmacklin%2Ffetch-through-merge-base/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rmacklin%2Ffetch-through-merge-base/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rmacklin%2Ffetch-through-merge-base/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rmacklin","download_url":"https://codeload.github.com/rmacklin/fetch-through-merge-base/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248384209,"owners_count":21094686,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-13T15:42:00.828Z","updated_at":"2025-10-07T14:45:31.769Z","avatar_url":"https://github.com/rmacklin.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# fetch-through-merge-base\n\nA GitHub Action for fetching PR commits through the merge-base\n\n## Usage\n\nBy default, the action will pull the \"base ref\" and \"head ref\" from the\n[`github` context], i.e. `${{ github.base_ref }}` and `${{ github.head_ref }}`.\n\nThis means usage can be as simple adding\n`- uses: rmacklin/fetch-through-merge-base@v0` to any `pull_request` workflow:\n\n```yml\nname: Example Workflow\non: pull_request\n\njobs:\n  example_job:\n    runs-on: ubuntu-latest\n    steps:\n      - uses: actions/checkout@v2\n        with:\n          ref: ${{ github.head_ref }}\n      - uses: rmacklin/fetch-through-merge-base@v0\n      # now we've fetched commits through the merge-base of the source branch\n      # and target branch of the pull request, so we can do things like:\n      - run: git merge-base ${{ github.base_ref }} ${{ github.head_ref }}\n      - run: git log --oneline ${{ github.base_ref }}..\n      - run: git diff --name-only ${{ github.base_ref }}...\n```\n\n[`github` context]: https://docs.github.com/en/actions/reference/context-and-expression-syntax-for-github-actions#github-context\n\nNote that the `${{ github.base_ref }}` and `${{ github.head_ref }}` properties\nare only available when the event that triggers the workflow is `pull_request`.\nSo, in order to use this action in a workflow that is triggered by a different\nevent, like `push`, the refs must be passed as inputs to the action. The\nfollowing example fetches commits through the merge-base of the `main` branch\nand the commit that triggered the workflow run:\n\n```yml\nname: Example Workflow\non: push\n\njobs:\n  example_job:\n    runs-on: ubuntu-latest\n    steps:\n      - uses: actions/checkout@v2\n      - uses: rmacklin/fetch-through-merge-base@v0\n        with:\n          base_ref: main\n          head_ref: ${{ github.sha }}\n```\n\n## More details\n\nThe default behavior of [`actions/checkout`] v2 is to only fetch a single commit\nbecause 1) often that commit is all that's needed and 2) fetching only one\ncommit is much faster than fetching everything, especially in large\nrepositories. If more history is needed, the `fetch-depth` input can be passed\nto `actions/checkout` to fetch a number of commits up to the current commit (or\nall history for all branches and tags via `fetch-depth: 0`). However, there's no\n\"fetch all commits within the current pull request\" option (the depth of which\ncan vary greatly from one pull request to another). That's what this action\naims to provide!\n\nThe way this action works is by iteratively [deepening] the history of the\nshallow clone until the common ancestor of the pull request source branch and\ntarget branch (i.e. the [`merge-base`]) has been found. By default, the action\nuses `--deepen=10`, but this can be tuned through the `deepen_length` action\ninput to optimize the `git fetch` calls for a given repository. The tradeoff of\nsetting a large `deepen_length` is that the action may fetch more unnecessary\ncommits when running on a pull request that only has a few commits. On the other\nhand, setting a small `deepen_length` may lead to many `git fetch` calls in a\nrow in order to fetch all the commits of a large PR, with each call incurring\nadditional overhead.\n\nNote: For small repositories, `actions/checkout` with `fetch-depth: 0` may\nfinish quickly, so feel free to just use that initially. This action can be\nswapped in later when the repository has grown to the point where fetching the\nfull history is slow.\n\n[`actions/checkout`]: https://github.com/actions/checkout\n[deepening]: https://git-scm.com/docs/git-fetch#Documentation/git-fetch.txt---deepenltdepthgt\n[`merge-base`]: https://git-scm.com/docs/git-merge-base\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frmacklin%2Ffetch-through-merge-base","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frmacklin%2Ffetch-through-merge-base","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frmacklin%2Ffetch-through-merge-base/lists"}