Tutorials

Find all repositories with unprotected default branches in GitHub

An unprotected default branch on GitHub can be a gateway for accidental or malicious changes, leading to potential vulnerabilities. Using the CloudQuery GitHub integration to sync your data to a PostgreSQL destination allows us to identify unprotected branches and continuously monitor for any new unprotected branches that may be created. After syncing data by following the instructions here, we can write a SQL query to find all the repositories in our organization that have unprotected default branches:

SELECT
repo.full_name,
pushed_at,
private,
branch.protected,
archived
FROM github_repositories repo
LEFT JOIN
github_repository_branches branch
ON branch.repository_id = repo.id
AND repo.default_branch = branch.name
WHERE
branch.protected = FALSE
AND archived != true
ORDER BY repo.name ASC;

This query lists all the repositories with unprotected default branches, filtering out any archived repositories. It also outputs when the last push to the repository happened, so we can gauge the importance and activity:

full_namepushed_atprivateprotectedarchived
cq-demo/unicorn-rainbow-pizza2024-06-06 13:20:21FalseFalseFalse
cq-demo/dancing-platypus2023-11-16 14:46:37TrueFalseFalse
cq-demo/invisible-taco2023-07-19 08:00:47TrueFalseFalse
cq-demo/sparkly-donut-ui2024-08-02 14:53:51FalseFalseFalse
cq-demo/ninja-kitten-analytics2024-05-22 17:15:08TrueFalseFalse

As we change the settings on the affected repositories to enable branch protection, we can re-run the CloudQuery sync and query to track our progress over time, and continuously monitor for any new repositories that have unprotected branches.

This is just one example of what's possible, there's a lot more we can do with all our GitHub data synced to a database. Check out the GitHub source integration documentation for a full list of all the available tables and more tips!

Want to see CloudQuery in action? Schedule a demo with our team or check out the platform documentation to learn more.

Want help getting started? Join the CloudQuery community to connect with other users and experts, or message our team directly here if you have any questions.

Try CloudQuery yourself

Self-hosted, open source, and free to start. Or schedule a demo to see the managed version.

Related posts

Tutorials

How to Automatically Update CloudQuery Integrations with Renovate

Configure Renovate to automatically update CloudQuery integration versions in your YAML files using the CloudQuery Hub API as a custom datasource.

Matthew M

Matthew M

May 20, 2026

AWS

Security

Tutorials

Finding AWS Unrestricted Outbound Access in 2026: EC2, Lambda, and Beyond

Find EC2, Lambda, and ECS Fargate resources with unrestricted outbound access in AWS using SQL. Why egress controls still break attack chains in 2026.

Joe Karlsson

Joe Karlsson

May 5, 2026

AWS

Security

Tutorials

AWS IAM Identity Center with Google Workspace as an IdP: 2026 Step-by-Step Guide

Set up AWS IAM Identity Center with Google Workspace: SAML authentication, SCIM user provisioning, and group sync with CLI or ssosync. Updated for 2026.

Joe Karlsson

Joe Karlsson

May 5, 2026

GCP

Security

Tutorials

Creating Cross-Project Service Accounts in GCP (Console + gcloud CLI)

Create a GCP service account that reads across all your projects with one credential. Covers gcloud CLI, org-level vs.

Joe Karlsson

Joe Karlsson

May 5, 2026

AWS

Cloud Infrastructure

Security

Tutorials

Integrate AbuseIPDB Threat Intelligence with CloudQuery

Enrich your cloud asset inventory with AbuseIPDB threat intelligence to identify public cloud IPs with known abuse reports.

Joe Karlsson

Joe Karlsson

April 20, 2026

AWS

Cloud Infrastructure

Tutorials

How to Query ipinfo.io Data with CloudQuery

Learn how to enrich your cloud asset inventory with ipinfo.io IP geolocation and threat intelligence data using CloudQuery.

Joe Karlsson

Joe Karlsson

April 20, 2026

AWS

Security

Tutorials

AWS IAM Identity Center (Formerly AWS SSO): The Complete 2026 Guide

AWS IAM Identity Center replaced AWS SSO in 2022. Learn how to set it up, configure permission sets, use the AWS CLI, and audit access with CloudQuery.

Joe Karlsson

Joe Karlsson

April 6, 2026

AWS

Tutorials

AWS Pinpoint Is Being Deprecated: How to Assess Your Migration Scope

AWS Pinpoint reaches end of support October 2026. Query your Pinpoint usage across all accounts to find what needs migrating before the deadline.

Joe Karlsson

Joe Karlsson

March 24, 2026

Tutorials

Moving Data from PostgreSQL to MotherDuck

How to sync PostgreSQL data to MotherDuck using CloudQuery, with both one-off batch and continuous CDC streaming options for serverless analytics.

Herman Schaaf

Herman Schaaf

March 13, 2026

Own your pipeline.
Own your data.