October 28-30: GitHub Universe 2024 docs-internal megabranch (#52491)
Co-authored-by: isaacmbrown <isaacmbrown@github.com> Co-authored-by: Hector Alfaro <hectorsector@github.com> Co-authored-by: Isaac Brown <101839405+isaacmbrown@users.noreply.github.com> Co-authored-by: hubwriter <hubwriter@github.com> Co-authored-by: Vanessa <vgrl@github.com> Co-authored-by: Christopher Nguyen <91625426+nguyen-dows@users.noreply.github.com> Co-authored-by: Sophie <29382425+sophietheking@users.noreply.github.com> Co-authored-by: Felicity Chapman <felicitymay@github.com> Co-authored-by: Andrew Eisenberg <aeisenberg@github.com> Co-authored-by: Ben Ahmady <32935794+subatoi@users.noreply.github.com> Co-authored-by: Sam Browning <106113886+sabrowning1@users.noreply.github.com> Co-authored-by: David Staheli <1767415+davidstaheli@users.noreply.github.com> Co-authored-by: Sarita Iyer <66540150+saritai@users.noreply.github.com> Co-authored-by: sunbrye <sunbrye@github.com> Co-authored-by: Tim Rogers <timrogers@github.com> Co-authored-by: Felix Guntrip <stevecat@github.com> Co-authored-by: Sunbrye Ly <56200261+sunbrye@users.noreply.github.com> Co-authored-by: James Fletcher <42464962+jf205@users.noreply.github.com> Co-authored-by: Rachael Rose Renk <91027132+rachaelrenk@users.noreply.github.com> Co-authored-by: Jules <19994093+jules-p@users.noreply.github.com> Co-authored-by: Laura Coursen <lecoursen@github.com> Co-authored-by: Jules Porter <jules-p@users.noreply.github.com> Co-authored-by: Devraj Mehta <devm33@github.com> Co-authored-by: Kate Studwell <katestud@github.com> Co-authored-by: Katherine Oelsner <49968061+octokatherine@users.noreply.github.com> Co-authored-by: Rachael Sewell <rachmari@github.com> Co-authored-by: Tim Rogers <me@timrogers.co.uk> Co-authored-by: Arfon Smith <arfon@users.noreply.github.com>
This commit is contained in:
@@ -9,6 +9,7 @@ versions:
|
||||
children:
|
||||
- /about-github-cli
|
||||
- /quickstart
|
||||
- /using-multiple-accounts
|
||||
- /creating-github-cli-extensions
|
||||
- /using-github-cli-extensions
|
||||
- /github-cli-reference
|
||||
|
||||
@@ -88,6 +88,12 @@ You can change configuration settings and add aliases or extensions, to make {%
|
||||
|
||||
* Create or add custom commands with {% data variables.product.prodname_cli %} extensions. For more information, see "[AUTOTITLE](/github-cli/github-cli/using-github-cli-extensions)" and "[AUTOTITLE](/github-cli/github-cli/creating-github-cli-extensions)."
|
||||
|
||||
## Using {% data variables.product.prodname_cli %} with multiple accounts
|
||||
|
||||
If you have multiple accounts on the same {% data variables.product.github %} platform, such as {% data variables.location.product_location %}, you can authenticate to each one and switch between them using the `gh auth switch` command. See [gh auth switch](https://cli.github.com/manual/gh_auth_switch) in the {% data variables.product.prodname_cli %} manual.
|
||||
|
||||
If you need to use the {% data variables.product.prodname_cli %} across multiple {% data variables.product.github %} platforms, such as a personal account on {% data variables.product.prodname_dotcom_the_website %} and a {% data variables.enterprise.prodname_managed_user %} on {% data variables.enterprise.data_residency_site %}, see "[AUTOTITLE](/github-cli/github-cli/using-multiple-accounts)."
|
||||
|
||||
## Further reading
|
||||
|
||||
* [AUTOTITLE](/github-cli/github-cli/github-cli-reference)
|
||||
|
||||
32
content/github-cli/github-cli/using-multiple-accounts.md
Normal file
32
content/github-cli/github-cli/using-multiple-accounts.md
Normal file
@@ -0,0 +1,32 @@
|
||||
---
|
||||
title: Using the GitHub CLI across GitHub platforms
|
||||
intro: 'Learn how to run commands when you are authenticated to accounts on different {% data variables.product.github %} platforms.'
|
||||
shortTitle: Accounts across platforms
|
||||
versions:
|
||||
fpt: '*'
|
||||
ghes: '*'
|
||||
ghec: '*'
|
||||
topics:
|
||||
- CLI
|
||||
allowTitleToDifferFromFilename: true
|
||||
---
|
||||
|
||||
If you have accounts on multiple {% data variables.product.github %} platforms, such as a personal account on {% data variables.product.prodname_dotcom_the_website %} and a {% data variables.enterprise.prodname_managed_user %} on {% data variables.enterprise.data_residency_site %}, you can authenticate with `gh auth login` for each account.
|
||||
|
||||
You'll need to authenticate to run _any_ commands in a given environment. For example, even if you're running a command that only requires read access to a public repository on {% data variables.product.prodname_dotcom_the_website %}, you won't be able to use this command if you're only authenticated to an account on {% data variables.enterprise.data_residency_site %}. You should therefore authenticate to all accounts you want to use with the {% data variables.product.prodname_cli %}.
|
||||
|
||||
## How do I run commands for each account?
|
||||
|
||||
Once you've authenticated with multiple accounts, when you run a command, the {% data variables.product.prodname_cli %} can sometimes automatically detect which platform you're trying to access. In other cases, you'll need to provide more information in your command.
|
||||
|
||||
The {% data variables.product.prodname_cli %} **automatically detects** your intended account when you're in the context of a specific repository. For example, if you `cd` into your `my-repo` directory and run `gh repo view`, the command will target the correct platform for that repository.
|
||||
|
||||
The {% data variables.product.prodname_cli %} **can't automatically detect** your intended account when it doesn't have this context. For example, if you run `gh repo list` to list repositories for your account, the {% data variables.product.prodname_cli %} won't know which account you want to access. In cases like this:
|
||||
|
||||
* The {% data variables.product.prodname_cli %} will default to {% data variables.product.prodname_dotcom_the_website %}.
|
||||
* You can set the `GH_HOST` environment variable to change the default target for these kinds of requests. See [gh environment](https://cli.github.com/manual/gh_help_environment) in the {% data variables.product.prodname_cli %} manual.
|
||||
* Some commands allow you allow you to specify your target environment with the `--hostname` option, such as `gh api`, or pass the full URL for a repository, such as `gh pr view`.
|
||||
|
||||
## Can I use multiple accounts on the same platform?
|
||||
|
||||
You can also authenticate with multiple accounts on the same platform. To switch between these accounts, you can use the `gh auth switch` command. See [gh auth switch](https://cli.github.com/manual/gh_auth_switch) in the {% data variables.product.prodname_cli %} manual.
|
||||
Reference in New Issue
Block a user