Built-in git checkout may cover this use case
Buildkite now supports checkout customization directly in pipeline YAML, including skip checkout, shallow clones, sparse checkout, custom Git flags, SSH checkout secrets, and commit verification. For most checkout use cases, try the built-in configuration before adding this plugin. View git checkout configuration .
Custom Checkout Buildkite Plugin
[!NOTE] Some of this plugin’s features are now supported natively. Buildkite agent v3.136.0 and later support these on command steps:
checkout.skipin place ofskip_checkoutcheckout.depthandcheckout.flagsfor shallow clones and custom clone or fetch flags on the main repository. These only take effect when the agent runs withcheckout-override-mode=none. The defaultfrom-jobmode ignores them, and Buildkite hosted agents cannot usenonemode.If that’s all you use this plugin for, we recommend the native options. Keep using this plugin to check out multiple repositories, use custom checkout paths,
mirror_urlordelete_checkout, for shallow clones or custom flags on hosted agents or agents not running innonemode, or if your agents are older than v3.136.0. See Migrating from checkout plugins.
A Buildkite plugin for customizing repository checkouts in your pipeline. This plugin allows you to:
- Skip the default repository checkout
- Check out multiple repositories
- Configure custom checkout paths
Features
- 🚫 Skip default checkout
- 📁 Custom checkout paths
- 🔑 SSH key support
- 📦 Multiple repository support
- ♻️ Persistent agent support
Configuration
Basic Configuration
steps:
- label: "Skip checkout"
command: 'echo "Skipping checkout"'
plugins:
- custom-checkout#v1.9.0:
skip_checkout: true
Advanced Configuration
steps:
- label: "Custom repository checkout"
command: "buildkite-agent pipeline upload"
plugins:
- custom-checkout#v1.9.0:
skip_checkout: true
repos:
- url: "https://github.com/org/repo.git"
ref: "main"
Configuration Options
Plugin Options
| Option | Required | Default | Description |
|---|---|---|---|
skip_checkout |
false | false |
Skip the default repository checkout |
repos |
false | [] |
List of repositories to check out |
delete_checkout |
false | false |
Delete checkout directory after build |
checkout_path |
false | $BUILDKITE_BUILD_CHECKOUT_PATH |
Custom checkout path |
Repository Options
Each repository in the repos list can have the following options:
| Option | Required | Default | Description |
|---|---|---|---|
url |
true | Repository Git URL | |
mirror_url |
false | Optional mirror for faster cloning. A local path or file:// URL is used as a git clone --reference; anything else is cloned directly then the remote is repointed to url |
|
mirror_dissociate |
false | false |
Local mirror_url only. Adds --dissociate to the reference clone so the checkout doesn’t stay dependent on the mirror |
ref |
false | Branch, tag, or commit to checkout | |
clone_flags |
false | ["-v"] |
Additional flags for git clone |
fetch |
false | false |
Perform git fetch after clone, before checkout |
fetch_flags |
false | [] |
Additional flags for git fetch |
checkout_path |
false | Custom directory path for this repository |
Examples
Skip Default Checkout
steps:
- label: "Skip checkout"
command: 'echo "Skipping checkout"'
plugins:
- custom-checkout#v1.9.0:
skip_checkout: true
Custom Repository Checkout
steps:
- label: "Custom checkout"
command: "buildkite-agent pipeline upload"
plugins:
- custom-checkout#v1.9.0:
skip_checkout: true
repos:
- url: "https://github.com/org/repo.git"
Multiple Repositories
steps:
- label: "Multiple repos"
command: "./script.sh"
plugins:
- custom-checkout#v1.9.0:
skip_checkout: true
repos:
- url: "https://github.com/org/repo1.git"
ref: "main"
- url: "https://github.com/org/repo2.git"
ref: "dev"
Custom Checkout Paths
steps:
- label: "Custom paths"
command: "./script.sh"
plugins:
- custom-checkout#v1.9.0:
skip_checkout: true
repos:
- url: "https://github.com/org/repo1.git"
ref: "main"
checkout_path: "/tmp/repo1"
- url: "https://github.com/org/repo2.git"
ref: "dev"
checkout_path: "repo2"
Clone with Mirror URL
steps:
- label: "Checkout with mirror"
command: "buildkite-agent pipeline upload"
plugins:
- custom-checkout#v1.9.0:
skip_checkout: true
repos:
- url: "https://github.com/org/repo.git"
mirror_url: "https://git-mirror.local/org/repo.git"
ref: "main"
Clone with Local Mirror (git object reference)
If mirror_url points to a path that already exists on the agent (a local path, or a file:// URL), it’s used as a git clone --reference against url instead of being cloned directly. This shares objects from a local mirror/cache to speed up clones and save disk, without changing the remote. If the path doesn’t exist or the reference clone fails, it falls back to a plain clone of url.
The plugin holds an exclusive <mirror_path>.customcheckout.lock directory lock during the reference clone. Relative paths are resolved from the build checkout directory; symlinks are resolved before choosing the lock path. Mirror writers must create and remove the same lock directory around updates. If the lock is busy or cannot be created, the plugin immediately falls back to a plain clone of url without reading the mirror.
The lock is released when the reference clone exits. A force-killed process (SIGKILL) can leave a stale lock directory. Remove it manually after confirming no clone or mirror writer is using it. Until then, builds use plain clones.
steps:
- label: "Checkout with local mirror reference"
command: "buildkite-agent pipeline upload"
plugins:
- custom-checkout#v1.9.0:
skip_checkout: true
repos:
- url: "https://github.com/org/repo.git"
mirror_url: "/var/cache/git-mirrors/repo.git"
mirror_dissociate: true
ref: "main"
mirror_dissociate: true adds --dissociate, so Git copies the objects it needs out of the mirror right away instead of keeping the checkout dependent on the mirror’s objects persisting — use it if the mirror could be deleted, garbage-collected, or otherwise mutated after this build’s checkout completes. This only applies to fresh clones — a reused checkout on a persistent agent keeps depending on the mirror even if you enable it afterward. To remove the dependency, recreate the checkout, or dissociate it manually (git -C <checkout_path> repack -a -d, then remove .git/objects/info/alternates), before removing the mirror.
Shallow Clone with Fetch
steps:
- label: "Shallow clone with fetch"
command: "buildkite-agent pipeline upload"
plugins:
- custom-checkout#v1.9.0:
skip_checkout: true
repos:
- url: "https://github.com/org/repo.git"
fetch: true
clone_flags:
- "--depth=1"
- "--branch=main"
fetch_flags:
- "--depth=1"
Pull Request Merge Refspec
When BUILDKITE_PULL_REQUEST_USING_MERGE_REFSPEC is enabled in your pipeline, the plugin automatically fetches and checks out GitHub’s pre-computed merge commit (refs/pull/N/merge) instead of the PR head commit. This tests the result of merging the PR into its target branch.
This activates when all of the following are true:
BUILDKITE_PULL_REQUEST_USING_MERGE_REFSPECistrue- The build is for a pull request (
BUILDKITE_PULL_REQUESTis a number) - The repository URL matches
BUILDKITE_REPO - No explicit
refis configured for the repository
When using multiple repositories, merge refspec only applies to the repository that triggered the build. An explicit ref always takes precedence.
Compatibility
| Elastic Stack | Agent Stack K8s | Hosted (Mac) | Hosted (Linux) | Notes |
|---|---|---|---|---|
| ✅ | ✅ | ✅ | ✅ | n/a |
- ✅ Fully supported (all combinations of attributes have been tested to pass)
- ⚠️ Partially supported (some combinations cause errors/issues)
- ❌ Not supported
Developing
Run all tests:
docker compose run --rm tests
Run linter:
docker compose run --rm lint
Contributing
- Fork the repository
- Create your feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request
📜 License
The package is available as open source under the terms of the MIT License.