Precedence Order
Settings are applied with the following precedence:Repository Settings
Highest priority - Settings in
.github/repos/<repo-name>.yml override all other levelsSub-Organization Settings
Middle priority - Settings in
.github/suborgs/*.yml override org-level defaultsThe precedence order is: Repository > Sub-Organization > OrganizationAs noted in the codebase: “The precedence order is repository > suborg > org (.github/repos/.yml > .github/suborgs/.yml > .github/settings.yml)“
How Configuration Merging Works
Safe Settings uses a deep merge algorithm implemented inlib/mergeDeep.js. Here’s how it works:
Deep Merge Algorithm
The merge algorithm follows these rules:- Objects are merged recursively - Nested settings are combined at every level
- Arrays are merged by name - Array elements with the same
namefield are merged together - Primitives are overwritten - Simple values from higher precedence levels replace lower ones
- Null values are preserved - Setting a value to
nullexplicitly disables it
Merge Example
Let’s see how settings are merged for a repository calledapi-gateway that belongs to the backend-team suborg:
Merge Behavior by Data Type
Objects
Objects are merged recursively. Properties from higher precedence levels are merged into properties from lower levels.Arrays
Arrays are merged by matching elements with the same identifying field (usuallyname, username, or login).
- Named Arrays
- Simple Arrays
Arrays with elements that have a
name field are merged by name:Primitives
Primitive values (strings, numbers, booleans) from higher precedence levels completely replace values from lower levels.Configuration Loading Process
When Safe Settings processes a repository, it follows these steps:Load Organization Config
Read
.github/settings.yml from the admin repository. This provides the baseline configuration.Check SubOrg Membership
Determine if the repository belongs to any sub-organization by:
- Matching repository name against
suborgrepospatterns - Checking if repository has teams listed in
suborgteams - Checking if repository has custom properties matching
suborgproperties
Load and Merge SubOrg Config
If the repository belongs to a suborg, load the suborg config and deep merge it with the org config.
Load and Merge Repo Config
Load
.github/repos/<repo-name>.yml (if it exists) and deep merge it with the previous result.Configuration Scope
Not all settings can be configured at all levels:Organization-Targeted Settings
Some settings only apply at the organization level:- Rulesets with
repository_nameconditions (these apply to multiple repositories)
.github/settings.yml and cannot be overridden at suborg or repo level.
Repository-Targeted Settings
Most settings apply to individual repositories and can be configured at all three levels:- Repository settings (visibility, features, etc.)
- Branch protection rules
- Teams and collaborators
- Labels and milestones
- Environments
- Custom properties
- And more…
Validation and Override Rules
You can define custom validators in your deployment settings to control which overrides are allowed:- Override Validators
- Config Validators
Prevent suborg or repo settings from weakening org-level security:
deployment-settings.yml
Preventing Configuration Drift
Safe Settings actively prevents configuration drift through webhook events:- When settings are changed directly in GitHub UI, Safe Settings receives an event
- It compares the current settings with the configuration in the admin repo
- If differences are detected, it syncs the settings back to match the configuration
- This ensures your configuration files remain the source of truth
How does Safe Settings detect changes?
How does Safe Settings detect changes?
Safe Settings listens to webhook events like:
repository.edited- When repository settings are changedbranch_protection_rule- When branch protection is modifiedrepository_ruleset- When rulesets are changedmember_change_events- When team/collaborator access changes
Can I temporarily bypass Safe Settings?
Can I temporarily bypass Safe Settings?
No, Safe Settings is designed to enforce your policies consistently. However, you can:
- Update your configuration files and create a PR to make changes
- Define bypass actors in rulesets who can make emergency changes
- Temporarily disable Safe Settings if absolutely necessary (not recommended)
What happens during the sync process?
What happens during the sync process?
Safe Settings uses an intelligent comparison algorithm that:
- Fetches current settings from GitHub
- Compares them with your configuration
- Identifies additions, modifications, and deletions
- Only makes API calls if there are actual changes
- Creates a check run with the results
Next Steps
Org Settings
Configure organization-wide defaults
SubOrg Settings
Group repositories and apply team-specific policies
Repo Settings
Override settings for individual repositories
Deployment Settings
Configure validators and restrictions