Skip to main content

Enterprise Server 3.23 目前作为发布候选版本提供。

Skip to content

Using multiple accounts in GitHub Desktop

Sign in to more than one account on the same host, and choose which account GitHub Desktop uses for each repository.

About multiple accounts

You can sign in to GitHub Desktop with more than one account on the same host. For example, you can use a personal account and a work account on GitHub.com, or several accounts on GitHub Enterprise Server or GHE.com. You don't need to sign out of one account to use another.

A repository in GitHub Desktop can be assigned to one account on the repository's host. GitHub Desktop uses the assigned account for GitHub API requests and for HTTPS authentication when Git pushes, pulls, or fetches.

Copilot features in GitHub Desktop, such as generating commit messages, use the repository's account if it has access to Copilot. Otherwise, they use another signed-in account that does.

If you used GitHub Desktop before multiple accounts were supported, each of your existing repositories is assigned to the account you were signed in to on that host. If you only use one account, nothing changes.

注意

The account assigned to a repository doesn't change the name and email address that Git uses as the author of your commits. For more information, see 配置 Git 用于 GitHub Desktop.

Adding another account

  1. 在菜单栏中,选择“GitHub Desktop”,然后单击“设置”********。

    Mac 上的菜单栏的屏幕截图。 在打开的“GitHub Desktop”下拉菜单下,光标悬停在“设置”上,该设置以蓝色突出显示。

  2. In the "Settings" window, on the Accounts pane, click Add GitHub.com account. To sign in to GitHub Enterprise Server or GHE.com, click Add GitHub Enterprise account instead.

    Screenshot of the "Accounts" pane in "Settings" on a Mac. Two GitHub.com accounts are listed. "Add GitHub.com account" is outlined in dark orange.

  3. Follow the prompts to sign in. See 在 GitHub Desktop 中向 GitHub 进行身份验证.

    提示

    Your browser might ask which GitHub account to use, even if you're already signed in. Choose the account you want to add, or sign in to a different account.

  1. 使用文件”菜单,然后单击“选项” 。

    Windows 上的“GitHub Desktop”菜单栏的屏幕截图。 在展开的“文件”下拉菜单中,以橙色框出了“选项”项。

  2. In the "Options" window, on the Accounts pane, click Add GitHub.com account. To sign in to GitHub Enterprise Server or GHE.com, click Add GitHub Enterprise account instead.

    Screenshot of the "Accounts" pane in "Options" on Windows. Two GitHub.com accounts are listed. "Add GitHub.com account" is outlined in dark orange.

  3. Follow the prompts to sign in. For more information, see 在 GitHub Desktop 中向 GitHub 进行身份验证.

    提示

    Your browser might ask which GitHub account to use, even if you're already signed in. Choose the account you want to add, or sign in to a different account.

The "Accounts" pane lists your GitHub.com accounts under "GitHub.com". Your GitHub Enterprise Server and GHE.com accounts are listed under "GitHub Enterprise", grouped by hostname.

How GitHub Desktop chooses an account for a repository

GitHub Desktop assigns an account to a repository when you clone, add, or publish it.

  • Cloning from the "GitHub" tab: Choose an account from the Account dropdown menu at the top of the "Clone a Repository" window. This dropdown menu only appears if you're signed in to more than one account. The list shows the repositories that account can access. When you clone, the repository is assigned to that account. For more information, see 从 GitHub Desktop 克隆和派生存储库.
  • Cloning from the "URL" tab, or adding a local repository: GitHub Desktop checks which of your accounts on the repository's host can access the repository.
    • If one account can access it, the repository is assigned to that account.
    • If more than one account can access it, GitHub Desktop asks you to choose. Every account can access a public repository, so you're always asked to choose if you're signed in to more than one account on its host.
    • If none of your accounts can access it, the repository is added without an assigned account. If you're cloning a private repository over HTTPS, the clone fails.
  • Publishing a repository: Choose an account from the Account dropdown menu in the "Publish Repository" window. If the repository's assigned account is signed in, that account is selected. For more information, see 使用 GitHub Desktop 添加现有项目到 GitHub.

Choosing an account when GitHub Desktop asks

If a repository doesn't have an assigned account, the "Repository account" window opens when GitHub Desktop needs one. For example:

  • Git needs HTTPS credentials to push or pull.
  • GitHub Desktop refreshes pull requests or creates a fork.

Background fetches never open this window. If you aren't signed in to any account on the repository's host, GitHub Desktop asks you to sign in instead.

If the repository's assigned account is signed out, the "Repository account" window asks you to sign in to that account. Click Sign in to sign in again. If you're signed in to another account on the same host, you can click Choose another account to assign that account to the repository instead.

To choose an account for a repository that doesn't have one:

  1. In the "Repository account" window, select the Account dropdown menu, then click the account you want to use for this repository. The list only shows accounts on the repository's host.

    If the account you want isn't listed, click Cancel, sign in to the account, then try again. For more information, see Adding another account.

    Screenshot of the "Repository account" window on a Mac. It asks which account to use for Spoon-Knife on GitHub.com, with an "Account" dropdown.

    Screenshot of the "Repository account" window on Windows. It asks which account to use for Spoon-Knife on GitHub.com, with an "Account" dropdown.

  2. Click Use account.

Changing the account for a repository

You can change the account for any repository that has a remote on GitHub.com, GitHub Enterprise Server, or GHE.com. You can only choose accounts that are signed in to the repository's host.

Using repository settings

  1. 在菜单栏中,选择“存储库”,然后单击“存储库设置...”。

    Mac 上的菜单栏的屏幕截图。 在展开的“存储库”下拉菜单中,光标悬停在“存储库设置”上,后者呈蓝色突出显示。

    Windows 上的“GitHub Desktop”菜单栏的屏幕截图。 在打开的“仓库”下拉菜单中,框出了“仓库设置”选项。

  2. In the "Repository Settings" window, on the Remote pane, select the Account dropdown menu, then click the account you want to use.

    To remove the repository's account, click None (unassigned).

    Screenshot of the "Remote" pane in the "Repository Settings" window on a Mac. The "Account" dropdown is outlined in dark orange.

    Screenshot of the "Remote" pane in the "Repository settings" window on Windows. The "Account" dropdown is outlined in dark orange.

  3. Click Save.

Using the repository list

If a repository has a remote on a GitHub host and there's more than one account to choose from, you can switch the repository's account from the repository list.

  1. In the repository bar, click Current Repository.

  2. Right-click the repository, select Account, then click the account you want to use.

    The current account has a checkmark. If the current account is signed out, it's listed as "@USERNAME (Signed out)".

    Screenshot of a repository's context menu in the repository list on a Mac. The "Account" submenu is open and shows two accounts.

    Screenshot of a repository's context menu in the repository list on Windows. The "Account" submenu is open and shows two accounts.

You can also open a repository's settings from the same context menu. Right-click the repository, then click Repository Settings….

Signing out of an account

When you sign out of an account that has repositories assigned to it, GitHub Desktop asks whether to keep those assignments.

  1. 在菜单栏中,选择“GitHub Desktop”,然后单击“设置”********。

    Mac 上的菜单栏的屏幕截图。 在打开的“GitHub Desktop”下拉菜单下,光标悬停在“设置”上,该设置以蓝色突出显示。

  2. In the "Settings" window, on the Accounts pane, next to the account you want to sign out of, click Sign Out.

  3. If repositories are assigned to the account, choose what happens to them in the "Sign out of @USERNAME?" window.

    • To keep the assignments, leave Clear repository account assignments deselected. When you sign in to the account again, GitHub Desktop uses it for these repositories again.
    • To remove the assignments, select Clear repository account assignments. GitHub Desktop asks you to choose an account the next time it needs credentials for these repositories.

    Screenshot of the "Sign out of @octocat?" window on a Mac, with a "Clear repository account assignments" checkbox.

  4. Click Sign out.

  1. 使用文件”菜单,然后单击“选项” 。

    Windows 上的“GitHub Desktop”菜单栏的屏幕截图。 在展开的“文件”下拉菜单中,以橙色框出了“选项”项。

  2. In the "Options" window, on the Accounts pane, next to the account you want to sign out of, click Sign out.

  3. If repositories are assigned to the account, choose what happens to them in the "Sign out of @USERNAME?" window.

    • To keep the assignments, leave Clear repository account assignments deselected. When you sign in to the account again, GitHub Desktop uses it for these repositories again.
    • To remove the assignments, select Clear repository account assignments. GitHub Desktop asks you to choose an account the next time it needs credentials for these repositories.

    Screenshot of the "Sign out of @octocat?" window on Windows, with a "Clear repository account assignments" checkbox.

  4. Click Sign out.

If the account’s token is no longer valid and GitHub Desktop removes the account, the repository assignments are kept.

Further reading