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

1

6

I am planning on utilizing GitPython for my project. When I test it out, using this code I am receiving an error.

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

The error is:

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 that last line. However, if I manually run git push --porcelain origin from the command line, I receive the error:

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

This is a fair error. It's a brand new repository and I haven't fully configured yet. However, I plan on deploying this project (and the ability to push) across multiple machines so I'd prefer to be able to do automatically via GitPython.

How can I set the username and password (or utilize an SSH key) to push to the remote repository?

Iconostasis answered 3/8, 2014 at 20:29 Comment(2)
@user319862 I did not. No. Sorry.Iconostasis
Without the full URL actually used here, it's difficult to reproduce. As far as I can tell, github authentication works fine as long as the URL is valid.Clegg
C
0

you need to push atleast once manually(i.e git push -u origin <branch_name>) so that your local repo is recognized on the remote side after doing this for first time you wont see this issue again

Commensal answered 26/5, 2021 at 18:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.