在 GitHub CLI 中切换用户

san*_*ser 7 git windows-10 github-cli

我正在使用 GitHub CLI 和MinGit for Windows

当我注销 GitHub CLI 并gh auth logout通过调用 git 使用不同的帐户重新登录时,gh auth login配置不会更改。

当我输入时,条目git config --global --list仍然指向旧帐户。因此,当我提交时,看起来提交是由我的旧帐户进行的。user.nameuser.email

我知道我可以输入git config --global user.name "username"并更改名称,但如何使用 GitHub CLI 正确执行此操作?

如果我无法使用 GitHub CLI 执行此操作,我需要user.name更改user.email的唯一两个条目才能作为我的新帐户提交?

Jus*_*mer 6

设置环境变量GH_CONFIG_DIR允许您更改 gh cli 查找授权/凭据的位置。

这意味着您可以使用 DirEnv 这样的工具在每个项目/目录中设置不同的 GitHub 授权。

例如:

cd project_dir/
echo $GH_CONFIG_DIR # likely returns blank
gh auth status # will show you logged in to account 1

export GH_CONFIG_DIR=.config # set GH_CONFIG_DIR to local .config
gh auth status # will now show you not logged in to any account

gh auth login # you can now log in to account 2

Run Code Online (Sandbox Code Playgroud)


Kau*_*sam -1

在全球范围内更改您的提交者姓名和电子邮件

前任-:

git config --global user.name "John"
git config --global user.email "john@gmail.com"
Run Code Online (Sandbox Code Playgroud)

仅为下一次提交更改作者信息

git commit --author="John<john@gmail.com>"
Run Code Online (Sandbox Code Playgroud)

了解更多 -:https ://www.git-tower.com/learn/git/faq/change-author-name-email/