Piping credentails to git push

5,164

This would only work in the case of sequential prompts that are the immediate part of the script as per your example. However in the case of git your values are being passed to the process prior to any username / password prompt - probably while its doing everything (network, etc) before GIT_ASKPASS - For reference: https://git-scm.com/book/en/v2/Git-Internals-Environment-Variables

Share:
5,164

Related videos on Youtube

Anmol Singh Jaggi
Author by

Anmol Singh Jaggi

Updated on September 18, 2022

Comments

  • Anmol Singh Jaggi
    Anmol Singh Jaggi over 1 year

    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:[email protected]/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
    
  • Anmol Singh Jaggi
    Anmol Singh Jaggi almost 8 years
    So, is there any way to make it work?
  • aphorise
    aphorise almost 8 years
    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.