This workflow shows a simple bulk-delete pattern usingDocumentation Index
Fetch the complete documentation index at: https://xata.io/docs/llms.txt
Use this file to discover all available pages before exploring further.
xata branch list --json, jq, and bash. The example deletes stale gh-readonly-queue* branches older than 1 hour, but the same pattern works for any bulk-delete use case — for example, cleaning up branches by naming convention, age, region, or any other attribute exposed by the Xata CLI.
The pattern in this guide is intentionally minimal. It does not require TypeScript, the Xata SDK, or any custom scripts — only the Xata CLI, jq, and a short bash loop in a scheduled GitHub Actions workflow.
Workflow configuration
Authentication and environment variables
The workflow requires the following environment variables:XATA_API_KEY: Your Xata API key (set as a GitHub secret).XATA_ORGANIZATIONID: Your Xata organization ID.XATA_PROJECTID: Your Xata project ID.
Workflow steps
1. Install the Xata CLI
PATH. jq is preinstalled on ubuntu-latest runners and does not require a separate install step.
2. List branches as JSON
--json flag returns the full branch list as a JSON array, including name, id, createdAt, and other metadata. This output is the input to the filter pipeline.
3. Filter with jq
- Have a name starting with
gh-readonly-queue. - Were created more than 1 hour ago (
now - 3600seconds).
4. Delete with a bash loop
xata branch delete --yes against it. The --yes flag is required in non-interactive environments such as GitHub Actions to skip the confirmation prompt.
Customizing the filter
The same pipeline works for any bulk-delete rule. Replace thejq filter with whatever conditions match your use case:
- Match a different naming convention. Replace
startswith("gh-readonly-queue")withstartswith("preview-"),test("^pr-[0-9]+$"), or any regex that matches your branch names. - Change the age threshold. Replace
(now - 3600)with(now - 86400)for 1 day,(now - 604800)for 1 week, and so on. - Exclude protected branches. Add
select(.name != "main" and .name != "staging")to make sure important branches are never matched. - Combine conditions. Chain multiple
select(...)filters to express more specific rules.
Best practices
- Start with a narrow filter. Begin with a specific name prefix and an age threshold, then broaden the rule once you are confident.
- Protect important branches explicitly. Add
select(.name != "main" and .name != "staging")to your filter when running broader cleanups. - Dry-run before deleting. Replace the
xata branch deletecall withecho "$branch"and run the workflow manually withworkflow_dispatchto preview which branches would be deleted. - Schedule conservatively. Hourly is appropriate for short-lived branches such as merge-queue branches; daily or weekly is usually enough for most cleanup rules.
When to use
Use this workflow when you want to:- Automatically remove short-lived branches such as merge-queue or preview branches.
- Enforce branch retention policies based on age or naming.
- Bulk-delete branches matching any rule expressible with the Xata CLI output and
jq.
gh api) and deleting Xata branches that no longer have a corresponding upstream branch.
Related workflows
- Merge Readiness — For validating main branch status.
- Create Branch — For managing pull request branches.
- Branch CLI reference — Full reference for
xata branch listandxata branch delete.