Try git-credential-manager

Last updated on 2022-03-16, Wed, 03:19 PM

阅读中文版本

How I Found This

I am a user of several git platforms and hold more than one identity on one of them.

SSH is out of the question and will never be used in my lifetime.

So for me, credential management is a big problem: using shipped plaintext credential store is obviously too dangerous, but I don’t want to have to enter the password every time.

Then I happened to see a glimmer of hope in the comments section of Haruhi’s sometime tweet.

git-credential-manager is exactly what I want.

Installation

Please refer this .

Configuration

For gitea, it is recommended to specify the authentication source as generic beforehand.

#.gitconfig
[credential "example.com"]
	provider = generic

Windows

Use DPAPI to encrypt credentials. [1]

#.gitconfig
[credential]
	helper = C:/Program\\ Files\\ \\(x86\\)/Git\\ Credential\\ Manager/git-credential-manager-core.exe
	credentialStore = dpapi

If you don’t need to use it globally, please restore the credential.helper properties in your home directory to avoid any inconvenience.

Linux

Use GPG / pass for encryption. [2]

API by freedesktop.org frequently fails to communicate with gcm and will lose your credentials.

It is recommended to generate a separate key for encryption.

gpg --expert --full-gen-key

Initialize pass. Don’t contain spaces when entering Key ID.

Edit .gitconfig.

#.gitconfig
[credential]
	helper = /usr/local/bin/git-credential-manager-core
	credentialStore = gpg

Multi-User

Add username in front of the hostname in the remote url. [3]

Like this:

git clone https://username@github.com/username/repo.git

Limit the effective range of .gitconfig

Here you need to use git’s conditional includes feature.

Find the .gitconfig file in your $HOME / %HOME% directory and add

[includeIf "gitdir:/path/to/customize/"]
	path = /path/to/your/config

Adding / at the end is equivalent to a wildcard to /** , which will work for all subdirectories below.

The prefix ~/ is relative to the home directory, while ./ is relative to the directory this .gitconfig is located in.

Also, you can nest multiple .gitconfig files.

For duplicate configurations, the closer the file is to .git/config in the actual git repository, the higher its priority.

In this way, you can restrict your credential store settings to certain directories.

Done, once and for all.

Ref


Try git-credential-manager
https://blog.h3a.moe/en/src/d07537/
Author
H3arn
Posted on
2022-03-04, Fri, 12:19 AM
Updated on
2022-03-16, Wed, 03:19 PM
Licensed under