linuxgitpasswordsgit-credential-manager

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


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.


Solution

  • 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://user1@github.com/user1/myRepo1
                                       ^^^^^^
    
     cd /path/to/my/local/repo2
     git remote set-url origin https://user2@github.com/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.