[英]Using multiple git personal access tokens (PAT) with Credential Manager
我根據這個答案使用 git credentialmanager 但我找不到如何使用多個個人訪問令牌(PAT)的方法。
我有
Windows terminal
要點dotvim
://github.com/lkeersmaekers/dotvim的 dotvim 存儲庫我建立
Windows terminal
要點的 PAT (創建要點范圍)dotvim
存儲庫的 PAT (訪問公共存儲庫范圍) 第一次推送Windows terminal
時,git 按預期要求輸入用戶名/密碼(=PAT),推送成功,我可以在 ZAEA23489CE3AA9B6406EBB28E0CDA430 中看到憑證。
但是,在此后推送dotvim
存儲庫時,使用來自Windows terminal
的存儲憑據 (PAT),並且dotvim
推送失敗。
我不確定這里的最佳做法是什么。
git push
以使用正確的憑據。您可以在這里采取幾種不同的方法。 一種是使用gist
和repo
范圍創建單個令牌並普遍使用它。 該令牌確實可以訪問您的所有存儲庫,但如果您使用憑證助手,那么它會以加密方式存儲,並且風險不會太大。
Since you're actually using two different domains here ( github.com
and gist.github.com
), you can use separate tokens without a problem. 令牌存儲在域的范圍內,因此這里沒有沖突。 只需在其各自的域上使用每個憑據。
如果您想為不同的存儲庫使用不同的令牌,可以通過將credential.usehttppath
設置為 true 來實現。 That can also be scoped to a particular URL pattern (including wildcards) such that you it only applies to GitHub (eg, with git config --global credential.https://github.com/.usehttppath true
. Each repository will then have它自己的一組憑據,並且您可以存儲任意數量的令牌。但是,如果您有很多存儲庫,這可能會很快變得不方便。
最后,如果您只想為公共和私有訪問使用不同的令牌,您可以利用 GitHub 在您使用令牌時忽略用戶名這一事實為 GitHub 執行此操作。 因此,您可以通過在主機名前放置public@
來克隆公共存儲庫(例如,https://public@github.com/git/git.git ) and then using
private@` 用於私有存儲庫。 Git 的憑證助手將為這些假用戶名存儲單獨的憑證,並使用相應的令牌。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.