0

I am currently trying to push to Git via GitPython using HTTPS. I am able to do this successfully, but I am prompted to enter my username and password for every fetch, push, and pull operation.

I would like to have my username and password be entered as command line arguments as my script makes a couple of git interactions. This repo will be on probably 40+ servers as a method of config management, and I don't want to set up all the SSH keys especially since it will often be used from a user on the host that is not myself.

Does anyone know how to take context of the shell from the python script to programmatically enter my username and password (they are already in my code as variables from the command line) or a way to pass my username and password to GitPython so that the shell prompt never even happens?

git_repo = Repo.init(repo_dir)

origin = git_repo.remote('origin')

origin.fetch() # Shell prompted here for username and password

git_repo.heads.dev.checkout()

origin.pull() # Shell prompted here for username and password

git_repo.git.add([added_filename])
git_repo.git.commit(commit_message)

origin.push() # Shell prompted here for username and password
4
  • 2
    You can roll a new SSH key, specific to this application. And make the key available to a user that is not yourself.
    – J_H
    Commented Sep 25, 2017 at 15:13
  • Do you have any details/a link on some details to that? Thanks
    – Tyler R
    Commented Sep 25, 2017 at 15:22
  • 1
    There's help pages on github.com/settings/keys
    – J_H
    Commented Sep 25, 2017 at 15:26
  • I am actually using gitlab rather than github.
    – Tyler R
    Commented Sep 25, 2017 at 16:03

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.