Overview
GitHub Desktop uses feature flags to ship stable but not production-ready features. This system allows the team to deploy code without blocking on final design feedback while giving users the option to preview new functionality.Types of Features
Preview Features
A preview feature is:- Well-defined in scope
- Approved by team consensus to proceed
- Has details that need clarification or iteration
Currently focused on UI changes: new views, significant changes to existing views, and similar interface modifications.
Beta Features
A beta feature is:- Slated for an upcoming release
- Usably complete
- Needs more testing or real-world usage
- A superset of preview features
Beta features include all preview features plus additional functionality ready for wider testing.
Why Use Feature Flags?
Benefits of feature flagging:1
Faster iteration
Get working code shipped quickly without waiting for perfect solutions.
2
User feedback
Users can opt-in to preview features and provide early feedback.
3
Conservative evolution
Avoid unnecessary UI churn that frustrates users.
4
Easy rollback
Pull features before users get attached if they don’t work out.
Implementation
Core Functions
Fromapp/src/lib/feature-flag.ts:10:
Feature Hierarchy
Creating Feature Flags
Step 1: Add Feature Flag Function
Add a new function toapp/src/lib/feature-flag.ts:
Step 2: Use in Code
Check the feature flag at runtime to conditionally render features:Example: Pull Request Integration
See #3339 for a complete example of pull request integration using feature flags.
Example Feature Flags
Development-Only Features
Fromapp/src/lib/feature-flag.ts:78:
- Development build (
__DEV__ === true), OR GITHUB_DESKTOP_PREVIEW_FEATURES=1environment variable set
Beta Features
Fromapp/src/lib/feature-flag.ts:44:
- Development build, OR
- Preview features enabled, OR
- Beta release channel
Platform-Specific Flags
Fromapp/src/lib/feature-flag.ts:64:
Account-Based Flags
Fromapp/src/lib/feature-flag.ts:91:
- Account feature flags from GitHub API
- Account-specific settings
Always-On Features
Fromapp/src/lib/feature-flag.ts:87:
Testing Feature Flags
Enabling Preview Features
1
Set environment variable
2
Restart GitHub Desktop
Quit and relaunch the application for changes to take effect.
3
Verify features enabled
Check that preview features are now visible in the UI.
Disabling Preview Features
1
Remove environment variable
2
Restart GitHub Desktop
Quit and relaunch the application.
Development Mode
All preview and beta features are automatically enabled in development builds:Best Practices
Naming Conventions
Function Patterns
Simple boolean returnCode Organization
1
Separate code paths
Keep feature-flagged code in separate components or functions for easier removal.
2
Clear conditionals
Make feature flag checks obvious at call sites.
3
Document intentions
Add comments explaining when the flag should be removed.
Cleanup Process
When to Remove Flags
Remove feature flags when:- Feature is fully released and stable
- Feature is abandoned/removed
- Beta period is complete
Cleanup Steps
1
Remove feature flag function
Delete the flag function from
feature-flag.ts.2
Remove conditionals
Find all usages and remove the conditional logic.
3
Delete old code
Remove the deprecated/old implementation.
4
Update tests
Remove or update tests that checked both code paths.
Finding Usages
Global Disable Switch
TheDisable constant at the top of feature-flag.ts provides an emergency kill switch: