1
Whenever I execute git push
, I have to type my username and password at the prompt manually.
However, I want to automate this process.
So, I tried to pass the credentials to the command using piping:
printf 'username\npassword' | git push
but the prompt for username and password still don't go away!
Why is it not working?
Note:
I know that this can be done using:
git push 'https://username:password@github.com/username/repo.git'
but I'm interested in knowing what's wrong with the piping method?
Also, to confirm that this process works for other cases, I did an experiment.
I created a script b.py
:
b.py
:
#!/usr/bin/env python3
username = input()
password = input()
log = open("log.txt", "w")
print(username + "\n" + password, file=log)
Then, I executed printf 'abcd\nefgh' | ./b.py
in the terminal which did work as expected and resulted in the log file containing the username and password strings:
log.txt
:
abcd
efgh
So, is there any way to make it work? – Anmol Singh Jaggi – 2016-05-19T09:52:42.443
Not that I'm aware. Other than that the in-lined method you referenced where the credentials are part of the address. Also the other thing to bare in mind is git reliance on the transport used - since it does not manage that - so I'd imagine that there would also be separation there so piping would probably not be possible without resorting to additional hacks. – aphorise – 2016-05-19T11:13:36.243