Environment Mapping

Environment Mapping

Branch patterns help you automatically map your Git branches to the correct environment (Dev, Staging, Production, etc.). You can use either exact matching or regex patterns.

Pattern Types

1. Exact Match

Match the branch name exactly as written.

Example:

  • Pattern: main

  • Matches: main

  • Doesn't match: main-backup, feature/main

When to use: When you have specific branch names like main, master, production.

2. Regex Patterns

Use regular expressions for flexible matching.

Common Pattern Examples

Match branches starting with a prefix

PatternDescriptionMatchesDoesn't Match
^dev/Branches starting with "dev/"dev/feature-123 dev/bug-fixdevelopment/test my-dev/branch
^feature/Branches starting with "feature/"feature/login feature/paymentnew-feature/test feature
^hotfix/Branches starting with "hotfix/"hotfix/critical-bug hotfix/securityfix/hotfix/issue
^release/Branches starting with "release/"release/v1.0 release/2024-01pre-release/test

Key symbol: ^ means "start of the branch name"

Match specific branch names

PatternDescriptionMatchesDoesn't Match
^main$Exactly "main"mainmain-backup main/dev
^master$Exactly "master"mastermaster-old new-master
^(main|master)$Either "main" or "master"main mastermain-dev master-backup

Key symbol: $ means "end of the branch name"

Match branches with version numbers

PatternDescriptionMatchesDoesn't Match
^release/v\d+Releases starting with "v" + numberrelease/v1 release/v2.0release/version1 release/beta
^release/\d+\.\d+Releases with version formatrelease/1.0 release/2.5release/v1.0 release/beta

Key symbol: \d means "any digit (0-9)"

Match pull request branches

PatternDescriptionMatchesDoesn't Match
^pull/\d+GitHub pull request branchespull/123/merge pull/456/headpr/123 pull-request/123
^pr-\d+Custom PR branch formatpr-123 pr-456-fixpull/123 pr/123

Case-Insensitive Matching

Use the (?i) prefix to match branch names regardless of case (uppercase/lowercase).

PatternDescriptionMatchesDoesn't Match
(?i)^NEW1$Exactly "NEW1" (any case)NEW1, new1, New1, nEw1NEW2, NEW
(?i)^release/Branches starting with "release/" (any case)release/v1.0 RELEASE/v1.0 Release/v1.0releases/v1.0
(?i)^(main|master)$Either "main" or "master" (any case)main, MAIN, Main master, MASTERmain-dev master-old

Key symbol: (?i) at the start makes the entire pattern case-insensitive

Examples:

Case-sensitive^dev/matches "dev/feature" only
Case-insensitive(?i)^dev/matches "dev/feature", "DEV/feature", "Dev/feature"
Case-sensitive^main$matches "main" only
Case-insensitive(?i)^main$matches "main", "MAIN", "Main", "mAiN"

When to use: When your team uses inconsistent casing in branch names (e.g., some use release/, others use Release/, or RELEASE/)

Regex Symbols Reference

SymbolMeaningExampleMatches
^Start of branch name^devdev/feature ✅ my-dev ❌
$End of branch namemain$main ✅ main-old ❌
(?i)Case-insensitive flag(?i)^main$main MAIN Main ✅
.Any single characterdev.dev/ dev- dev1
*Zero or more of the previousdev.*dev dev/feature development
+One or more of the previousdev.+dev/feature ✅ dev ❌
\dAny digit (0-9)v\dv1 v2 v9
|OR (either/or)dev|qadev qa
[ ]Any character in brackets[0-9]0, 1, 2, ..., 9
( )Group patterns^(dev|qa)/dev/test qa/test
[^ ]Any character NOT in brackets[^0-9]a, b, - (not digits)

Best Practices

DOs

1. Use ^ to anchor at the start

^dev/(matches only branches starting with "dev/")
dev/(matches anywhere - could match "old-dev/test")

2. Use $ for exact matches

^main$(matches only "main")
^main(matches "main", "main-old", "maintenance")

3. Escape special characters

^release/v\d+.\d+(matches "release/v1.0")
^release/v\d+.\d+(. matches any character)

4. Test your patterns before using - Use the platform's pattern tester or tools like regex101.com (opens in a new tab)

5. Use (?i) for case-insensitive matching

(?i)^release/(matches "release/", "RELEASE/", "Release/")
^[Rr][Ee][Ll]...(complex and hard to maintain)

DON'Ts

1. Don't use patterns without anchors (unless intentional)

⚠️dev*(matches "d", "de", "dev", "u" in "pull")
^dev(matches branches starting with "dev")

2. Don't use special characters (security risk)

dev;echo(contains dangerous character ;)
devcmd(contains dangerous character `)

3. Don't make patterns too broad

.*(matches everything)
.+(matches any branch with at least 1 character)

Common Use Cases

Use Case 1: Traditional Git Flow

Production:^(main|master)$
Staging:^(staging|stage)$
Development:^(dev|develop)$
Features:^feature/
Hotfixes:^hotfix/
Releases:^release/

Use Case 2: Environment-based Prefixes

Production:^prod/
Staging:^stg/
QA:^qa/
Development:^dev/

Use Case 3: Team-based Branches

Team Alpha:^alpha/
Team Beta:^beta/
Shared:^shared/
Main:^main$

Use Case 4: Version-based Releases

Production:^release/v\d+.\d+.\d+$
Release Candidates:^release/v\d+.\d+.\d+-rc\d+$
Beta:^release/v\d+.\d+.\d+-beta$
Development:^develop$

Use Case 5: Case-Insensitive Environments

When your team uses inconsistent casing:

Production(?i)^(main|master)$matches main, MAIN, Main, master, MASTER
Staging(?i)^(staging|stage)$matches staging, STAGING, Staging
QA(?i)^qa/matches qa/, QA/, Qa/
Development(?i)^dev/matches dev/, DEV/, Dev/

Testing Your Patterns

Example: Testing ^dev/

Branch NameMatch?Reason
dev/feature-login✅ YesStarts with "dev/"
dev/bug-fix✅ YesStarts with "dev/"
development/test❌ NoStarts with "development/", not "dev/"
my-dev/branch❌ NoDoesn't start with "dev/"
feature/dev/test❌ NoDoesn't start with "dev/"

Example: Testing ^release/v\d+\.\d+

Branch NameMatch?Reason
release/v1.0✅ YesMatches pattern
release/v2.5✅ YesMatches pattern
release/v1.0.3✅ YesMatches pattern (and more)
release/version1.0❌ NoMissing "v" before number
release/beta❌ NoNo version number

Warnings vs Errors

The platform validates your patterns and provides:

Errors (Blocks saving)

  • Invalid characters: ;, &, `, ", ', <, >, %

  • Invalid regex syntax: Unclosed brackets, invalid escape sequences

Example:

dev;echo hack(contains dangerous character ;)
dev[test(unclosed bracket)

Warnings (Allows saving with notice)

  • Unanchored patterns: Patterns that might match unintentionally

Example:

⚠️dev*Warning: Will match "u" in "pull/ud/merge"

Suggestion: Use "^dev" instead

You can still use warned patterns if the behavior is intentional.

Need Help?

  • Regex Tester: regex101.com (opens in a new tab) (choose "ECMAScript/JavaScript" flavor)

  • Quick Tip: Start simple (exact match or ^prefix/) and add complexity only when needed

  • Questions? Contact support with your branch naming convention, and we'll help create the right patterns

Quick Reference Card

SymbolMeaningExample
^Start of name^dev → "dev/test" ✅
$End of namemain$ → "main" ✅
(?i)Case-insensitive(?i)^main$ → "main", "MAIN" ✅
\dAny digitv\d → "v1" ✅
\d+One or more digits\d+ → "123" ✅
.Any characterdev. → "dev/" ✅
.*Zero or more charsdev.* → "dev", "development" ✅
|ORdev|qa → "dev" or "qa" ✅
( )Group^(dev|qa)/ → "dev/" or "qa/" ✅
[abc]Any of a, b, or c[0-9] → digits ✅
[^abc]NOT a, b, or c[^0-9] → non-digit ✅