1

I am trying to use Gitpython in python on my virtual machine but struggle due to sudo and denied permissions etc. So instead I wanted to try a different approach. When I write sudo git pull it first asks me for the password, then for the git username, and then for the git password, what I want to do now i prefill those in some kind of os.system within python. This is what I have accomplished so far:

os.system("echo <password> | sudo -S git pull")

This solves the first problem with the sudo password. But how can I prefill answers for the questions the command line will return?

asked Feb 6, 2018 at 18:26

1 Answer 1

1

how can I prefill answers for the questions the command line will return?

By avoiding having to prefill anything.

Meaning, as root, you should be able to do a git pull without having to enter the username/password.
If you can do that as root, in a command line, you will then be able to make it work in a Python os.system("echo <password> | sudo -S git pull") call.

For that:

1/ First set the username in the remote URL itself

cd /path/to/repo
git remote -v
 https://aserver/auser/arepo
git remote set-url origin https://username@aserver/auser/arepo

2/ Use a credential helper (done as root) in order for Git itself to look for the password (instead of you having to try and feed it to the command line).

Once that is working as root, repeat the same git pull in your Python program (running as root)

answered Aug 31, 2018 at 20:56
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.