Skip to main content

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

From app/src/lib/feature-flag.ts:10:

Feature Hierarchy

Creating Feature Flags

Step 1: Add Feature Flag Function

Add a new function to app/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

From app/src/lib/feature-flag.ts:78:
Enabled when:
  • Development build (__DEV__ === true), OR
  • GITHUB_DESKTOP_PREVIEW_FEATURES=1 environment variable set

Beta Features

From app/src/lib/feature-flag.ts:44:
Enabled when:
  • Development build, OR
  • Preview features enabled, OR
  • Beta release channel

Platform-Specific Flags

From app/src/lib/feature-flag.ts:64:

Account-Based Flags

From app/src/lib/feature-flag.ts:91:
Enabled based on:
  • Account feature flags from GitHub API
  • Account-specific settings

Always-On Features

From app/src/lib/feature-flag.ts:87:
These flags exist for historical reasons or future flexibility. Consider removing them during cleanup if truly always enabled.

Testing Feature Flags

Enabling Preview Features

1

Set environment variable

Need help? See this guide for setting environment variables on different operating systems.
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

Or remove from your shell profile/system settings.
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 return
Arrow function for always-on
Platform-specific logic
Account-based logic

Code 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

The Disable constant at the top of feature-flag.ts provides an emergency kill switch:
Setting Disable = true turns off ALL preview and beta features, regardless of environment variables or build type. Use only in emergencies.

Testing and QA

Test Matrix

Features should be tested in all states:

Automated Tests