The Problem
As others have said, you can't pass arguments within the string. The whole string is interpreted as the command.
# this works
echo foo
# this does not
"echo foo"
Working Solution(s)
I went through every possible iteration of how to do this:
- SSH Public Keys
- API Access Tokens
- GIT_ASKPASS
- .gitconfig insteadOf
- .gitconfig [credential]
- .git-credentials
- .netrc
And I compiled a list of EVERY. SINGLE. METHOD. that actually worked.
I actually recommend the .gitconfig insteadOf approach, but for GIT_ASKPASS, this is what I did:
How to create an GIT_ASKPASS script:
echo 'echo $MY_GIT_TOKEN' > $HOME/.git-askpass
How to use it:
export MY_GIT_TOKEN=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
export GIT_ASKPASS=$HOME/.git-askpass
git clone https://token@code.example.com/project.git
The script receives stdin in the form of:
Password for 'scheme://host.tld':
The script receives Git ENVs such as:
GIT_DIR=/Users/me/project/.git
GIT_EXEC_PATH=/usr/local/Cellar/git/2.19.0_1/libexec/git-core
GIT_PREFIX=
More details in the cheatsheet.