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

1

4

One password is no problem

I wanted to store my credentials "safely" for use by git so I did as instructed here. This way I don't have to input password/PAT every single time, I perform any git operation.

  1. Install libsecret using sudo apt-get install libsecret-1-0 libsecret-1-dev

  2. Build the "credential manager" using sudo make --directory=/usr/share/doc/git/contrib/credential/libsecret

  3. and then configure my local git folder using git config --global credential.helper \ /usr/share/doc/git/contrib/credential/libsecret/git-credential-libsecret

Works superb.

How to do the above with many passwords?

What I don't get is how to do the same for many passwords associated with different accounts/repositories. I was suggested to use gcm core.

I tried installing gcm core as instructed here.

  1. Download .deb package

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

  3. configure the "credential store" git config credential.credentialStore secretservice (as I use libsecret).

  4. I removed the Credential helper pointing to /usr/share/doc/git/contrib/credential/libsecret/git-credential-libsecret from the local git config file.

It still doesn't work. When I try to push a repo, I get a garbled message with how to use git config followed by request to fill in credentials (shown here). I don't understand what I am doing! namely credential store, credential manager, secret-service and gcm core.

I looked here and here and I still don't get it.

Computation answered 5/5, 2021 at 16:28 Comment(0)
A
2

Any credential helper should follow the same process.

But if you have multiple account/password for the same domain (say github.com for instance), then you need to change your remote URL

 cd /path/to/my/local/repo1
 git remote set-url origin https://[email protected]/user1/myRepo1
                                   ^^^^^^

 cd /path/to/my/local/repo2
 git remote set-url origin https://[email protected]/user1/myRepo2
                                   ^^^^^^

That way, the credential helper will differentiate your different account.
Since gcm core is a bit fineky to install, test it first with the classic libsecret-based helper.

Antisana answered 5/5, 2021 at 17:24 Comment(9)
I tried it, but I still get the same garbled output followed by request to type password (not username though). When I type the password, it doesn't end up saving it.Computation
What does it mean to "test it first with classic libsecret-based helper"?Computation
@Computation The first part of your question, the one ending with "Works superb.": test it with that.Antisana
Just did... So the old repo which worked before still continues to work. Here the local git config credential.helper points to libsecret/git-credential-libsecret. Still works with the same "garbled error" (as shown here)Computation
@Computation What version of Git are you using? show-scope is Git 2.26 (Q1 2020): https://mcmap.net/q/13937/-where-do-the-settings-in-my-git-configuration-come-fromAntisana
2.25.1 is the version number.Computation
Am I using an advanced version of GCM core?Computation
@GCM core might be using an option of Git 2.26+. Can you upgrade first Git to 2.31.1? (lifeonubuntu.com/upgrading-ubuntu-to-use-the-latest-git-version)Antisana
Bro Hearty thanks. YOU DID IT. It is because of people like you that I can still use linux albeit strugglingly. IT WORKS. I needed two things: 1 is git remote set-url origin https://[email protected]/user1/myRepo1.git and the other is git 2.31. This seems to have done the trick... for both my usernames. I will update the answers. :) THANKS A TON.Computation

© 2022 - 2024 — McMap. All rights reserved.