I am trying to script a git pull without having to enter a username and password. How would I go about doing this? The only functionality I will be using from git is "git pull".
4 Answers
How are you connecting to the remote git repository? If you are using an http/https endpoint, read this document, which includes information about storing your username and password in a .netrc file.
You can also embed your username and password in your remote url.
A better choice, if you have the option, is to use ssh instead (a remote accessed via ssh looks like [email protected]:/path/to/repo). You can then set up ssh key-based authentication, which does not require a username and password.
Comments
You can do it like this is your .git/config:
[remote "origin"]
url = https://<user>:<pass>@github.com/whatever.git
for example.
2 Comments
Use the subprocess module to run git as an external command.
2 Comments
If you need to execute a command through a shell and interact with it sending input as if it was written from a terminal and getting the subsequent output, then you could use pexpect.