How do I set git username and password when using gitpython?

I am planning to use GitPython for my project. When I test it using this code, I get an error.

repo.index.add(['*']) 
repo.index.commit(message="Initial Commit")
repo.remotes.origin.push()

      

Mistake:

Traceback (most recent call last):
  File "test.py", line 24, in <module>
    repo.remotes.origin.push()
  File "C:\Python27\lib\site-packages\git\remote.py", line 627, in push
    return self._get_push_info(proc, progress or RemoteProgress())
  File "C:\Python27\lib\site-packages\git\remote.py", line 564, in _get_push_info
    finalize_process(proc)
  File "C:\Python27\lib\site-packages\git\remote.py", line 64, in finalize_process
    proc.wait()
  File "C:\Python27\lib\site-packages\git\cmd.py", line 100, in wait
    raise GitCommandError(self.args, status, self.proc.stderr.read())
git.exc.GitCommandError: 'git push --porcelain origin' returned exit status 128:

      

There is no message after this last line. However, if I manually run git push --porcelain origin

from the command line, I get the error:

fatal: could not read Username for 'https://github.com': No such file or directory

      

This is a fair mistake. This is a brand new repository and I am not fully configured yet. However, I am planning on deploying this project (and being able to push) across multiple machines, so I would prefer to be able to do this automatically via GitPython.

How do I set a username and password (or use an SSH key) to push to a remote repository?

+3


source to share





All Articles