在一个系统上为 Azure 配置 git 和 GitHUB 以及 BitBucket

Configure git for Azure and GitHUB and BitBucket on one system

我正在与不同的团队开展多个项目,并使用 GitHub、Azure 和 Bitbucket,我使用 VSCode 进行开发。 请问我如何为每个平台使用不同的个人设置,因为我为这些平台创建了不同的帐户。

目前我只有 GitHub 这个全局设置。

 git config --global user.name ande caleb
 git config --global user.email ande.caleb@microsoft.com 

我现在想包括 Azure 和 Bitbucket,但我不知道该怎么做。

有没有办法保留全局设置并仍然使用不同的凭据推送和提交到其他平台(azure、bitbucket)。

是的。

您可以为每个项目定义不同的用户名和电子邮件

--local

不是在全局定义配置,而是在每个项目本地定义它

git config --local user.name ande caleb
git config --local user.email ande.caleb@microsoft.com 

深度解释:

Git 商店配置是“级别”,这些“级别”(系统、全局、本地)中的每一个都会覆盖上一个级别中的值

因此,如果您在系统级别定义相同的配置,它将被在 global 定义的任何相同配置覆盖,并且 local 将覆盖那些 2

找出配置值的定义位置

--show-scope

从 Git 2.26.0 开始,您可以使用 --show-scope 选项:

https://github.com/git/git/blob/master/Documentation/RelNotes/2.26.0.txt

  • "git config" learned to show in which "scope", in addition to in which file, each config setting comes from.
git config --list --show-scope

--show-origin

git config --list --show-origin

这是配置及其位置的列表