After going over dozens of SO posts, blogs, etc, I tried out every method, and this is what I came up with. It covers EVERYTHING.
These are all the ways and tools by which you can securely authenticate git to clone a repository without an interactive password prompt.
- SSH Public Keys
- API Access Tokens
- .gitconfig insteadOf
- .gitconfig [credential]
- Bonus: Works with Private Packages
- node / npm package.json
- python / pip / eggs requirements.txt
- ruby gems Gemfile
- golang go.mod
Best options for no plaintext storage
From what's asked here either SSH Keys,
git credential store using the OS Keychain manager might be the best choice.
Since GIT_ASKPASS is probably the least understood of the 3, I'll detail that here - and the others are in the cheatsheet.
How to create an
echo 'echo $MY_GIT_TOKEN' > $HOME/.git-askpass
How to use it:
git clone https://firstname.lastname@example.org/project.git
The script receives stdin in the form of:
Password for 'scheme://host.tld':
The script receives Git ENVs such as:
More details in the cheatsheet.