Skip to content

Add multi-account support for GitHub.com in GitHub Desktop - #21467

Closed
Mahmadabid wants to merge 3 commits into
desktop:developmentfrom
Mahmadabid:development
Closed

Mahmadabid wants to merge 3 commits into
desktop:developmentfrom
Mahmadabid:development

Conversation

@Mahmadabid

@Mahmadabid Mahmadabid commented Jan 15, 2026 •

Copy link
Copy Markdown

Multi-Account Support for GitHub Desktop

Description

This PR introduces multi-account support for GitHub.com in GitHub Desktop. Users can now sign in with multiple GitHub accounts simultaneously and associate specific accounts with individual repositories. This ensures that commits and other actions are performed using the correct identity, even when multiple accounts are active.

Key Changes

Core Logic

  • RepositoryAccountStore: Created a new store to manage the mapping between repositories and preferred accounts. This store persists preferences using localStorage.
  • getAccountForRepository: Updated the account resolution logic to check for a repository-specific preference before falling back to the default behavior.
  • AppStore: Added setRepositoryAccount action to update preferences and trigger UI refreshes.

User Interface

  • CommitMessageAvatar: Updated to show a dropdown menu when multiple accounts are available for the current repository's endpoint, allowing users to switch identities easily.
  • CommitMessage & ChangesList: Wired up the new onSetRepositoryAccount callback through the component tree to enable the account switching interaction.

Sign-In Flow

  • SignInStore: Modified to allow adding new accounts without signing out of existing ones. Specifically, the "Existing Account" warning is now bypassed for GitHub.com to support multi-account addition seamlessly.

Testing

  • Unit Tests: Added comprehensive tests for RepositoryAccountStore and SignInStore to verify preference persistence and account addition flows.
  • Security: Verified that authentication tokens are stored securely and isolated per account using keytar logic (verified via multi-account-security-test.ts).

Fixes #3707

…e account selection

This commit introduces support for multiple accounts per endpoint, allowing users to sign in with multiple GitHub.com accounts (e.g., personal and work) simultaneously in Github Desktop. It updates account storage, token isolation, and UI to handle multiple accounts, adds a repository-account preference store, and provides new APIs for precise account lookup. The accounts preferences UI now lists all GitHub.com accounts and allows adding more, and users can select the preferred account for each repository. Comprehensive unit and security tests are included to verify correct behavior and token isolation.
@github-actions github-actions Bot added external Pull request originating outside of the Desktop core team triage For incoming issues labels Jan 15, 2026

@maifeeulasad maifeeulasad left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so far looks good to me

but, i think

  • a detailed test for validating username, user email is correct when switching between account should be done with more care
  • shall we group repo per user login??? just a question, asking

this.reset()
}

const existingAccount = this.accounts.find(isDotComAccount)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

care to explain the updated flow please?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously, beginDotComSignIn would check if a GitHub.com account already existed. If it did, it would transition to SignInStep.ExistingAccountWarning, effectively blocking the user from signing in with a second account unless they signed out of the first one.

The updated flow bypasses this check for GitHub.com. It now transitions directly to SignInStep.Authentication regardless of whether an account is already present. This change is the key enabler for multi-account support, allowing the user to initiate a new OAuth flow and add a second account alongside the existing one without interruption.

describe('beginDotComSignIn', () => {
it('starts authentication flow even if accounts exist (multi-account support)', async () => {
// Setup: Add an existing .com account
const existingAccount = new Account(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

care to explain these params please?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These parameters correspond to the constructor arguments for the Account model defined in app/src/models/account.ts. They are required to create a valid Account instance for the test.

In order, they represent:

  1. login: The username (e.g., 'existing-user').
  2. endpoint: The API URL (e.g., 'https://api.github.com/').
  3. token: The dummy OAuth token.
  4. emails: List of emails (empty array for this test).
  5. avatarURL: User's avatar URL (empty string).
  6. id: Unique user ID (1).
  7. name: Display name (empty string).
  8. plan: (Optional) Account plan (e.g., 'free').

I'm manually constructing this mock account to simulate a pre-existing user session in the store before verifying the multi-account sign-in logic

@Mahmadabid

Copy link
Copy Markdown
Author

Hi @maifeeulasad

so far looks good to me

but, i think

  • a detailed test for validating username, user email is correct when switching between account should be done with more care
  • shall we group repo per user login??? just a question, asking

You're right, we should add explicit tests verifying that when switching the preferred account for a repository, the commit author info (username, email) correctly reflects the newly selected account.

Regarding grouping repositories per user login: The current design maintains a flat list of repositories where each repo's preferred account is managed via the RepositoryAccountStore. While we could certainly implement grouping to visualize this relationship better, I think it’s best to leave that for a later UI/UX refinement pass. This keeps the current PR focused on the core multi-account logic and storage implementation

Expanded RepositoryAccountStore tests to cover multi-account switching, ensuring correct association of usernames, emails, and names per repository. Added tests for independent account preferences across repositories and for correct account lookup after switching. Also improved documentation in SignInStore tests for account constructor parameters.
@Mahmadabid

Copy link
Copy Markdown
Author

Hey @maifeeulasad
I have added comprehensive tests for multi-account switching.

@maifeeulasad

Copy link
Copy Markdown
Contributor

Hey @Mahmadabid , I think you take a look into session partion as well. That would be more helpful. Just dropping a link which you may find helpful and resolve some more issues.

ref:

@tidy-dev

Copy link
Copy Markdown
Contributor

Hi @Mahmadabid, thanks for working on this PR and attempting to address this long-standing feature request.

After reviewing this, we've decided we need to reserve multi-account support for the internal team. This feature touches critical authentication systems and has many intricate edge cases that require deep coordination with our product, design, and security teams, including:
- Identity management across GitHub.com and GitHub Enterprise Server accounts
- Account switching workflows and their impact on repository state
- Token storage, refresh, and security implications across multiple accounts
- UI/UX patterns for account selection at different stages of Git operations
- Migration paths for existing users with complex authentication setups
- Handling account permissions and scope differences

Given the scope and complexity, we need to own this implementation end-to-end to ensure it meets Desktop's quality bar and integrates with our broader roadmap.

We're closing this PR but keeping #3707 open to continue tracking this highly-requested feature as we work on our own solution.

For future contributions, we recommend checking with the Desktop team before starting work on significant features. Issues marked with help wanted are great opportunities for external contributions where the approach and scope is already clear or determined. Thanks for understanding!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

external Pull request originating outside of the Desktop core team triage For incoming issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature: Options > Git > manage multiple accounts

3 participants