如何存储多个 PATs/passwords 供 git 使用?

How to store multiple PATs/passwords for use by git?

一个密码没问题

我想“安全地”存储我的凭据以供 git 使用,所以我按照指示做了 here。这样我就不必每次都输入 password/PAT,我执行任何 git 操作。

  1. 使用 sudo apt-get install libsecret-1-0 libsecret-1-dev

    安装 libsecret
  2. 使用sudo make --directory=/usr/share/doc/git/contrib/credential/libsecret

    构建“凭证管理器”
  3. 然后使用 git config --global credential.helper \ /usr/share/doc/git/contrib/credential/libsecret/git-credential-libsecret

    配置我的本地 git 文件夹

作品精湛。

上面的密码很多怎么办?

我不明白的是如何对多个密码执行同样的操作 与不同 accounts/repositories。我被建议使用 gcm 核心。

我尝试按照说明安装 gcm core here

  1. 下载.deb包

  2. sudo dpkg -i <path-to-package> git-credential-manager-core configure

  3. 配置“凭据存储”git config credential.credentialStore secretservice(因为我使用 libsecret)。

  4. 我删除了 Credential helper 指向 /usr/share/doc/git/contrib/credential/libsecret/git-credential-libsecret 来自本地 git 配置文件。

还是不行。 当我尝试推送 repo 时,出现乱码 有关如何使用 git config 的消息,然后是填写请求 凭据(显示 here)。我不明白我在做什么!即 credential storecredential managersecret-servicegcm core.

我看了 and ,还是没看懂。

任何凭据助手都应遵循相同的过程。

但是如果您有多个 account/password 用于同一个域(例如 github.com),那么您需要更改远程 URL

 cd /path/to/my/local/repo1
 git remote set-url origin https://user1@github.com/user1/myRepo1
                                   ^^^^^^

 cd /path/to/my/local/repo2
 git remote set-url origin https://user2@github.com/user1/myRepo2
                                   ^^^^^^

这样,凭据助手将区分您的不同帐户。
由于 gcm 核心安装起来有点麻烦,请先使用经典的基于 libsecret 的帮助程序对其进行测试。