在使用gitpython时,如何设置git用户名和密码?

在使用gitpython时,如何设置git用户名和密码?,python,git,gitpython,Python,Git,Gitpython,我计划在我的项目中使用GitPython。当我测试它时,使用这段代码我收到了一个错误 repo.index.add(['*']) repo.index.commit(message="Initial Commit") repo.remotes.origin.push() 错误是: Traceback (most recent call last): File "test.py", line 24, in <module> repo.remotes.origin.pus

我计划在我的项目中使用GitPython。当我测试它时,使用这段代码我收到了一个错误

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

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:
这是一个公平的错误。这是一个全新的存储库,我还没有完全配置。然而,我计划在多台机器上部署这个项目(以及推送功能),因此我更希望能够通过GitPython自动完成


如何设置用户名和密码(或使用SSH密钥)以推送到远程存储库

您需要手动推送至少一次(即git push-u origin),以便在第一次这样做后,您的本地回购在远程端被识别。您不会再看到这个问题了。

您有没有发现这个问题?@user319862我没有。没有。对不起。如果这里没有实际使用的完整URL,很难复制。据我所知,只要URL有效,github身份验证就可以正常工作。
fatal: could not read Username for 'https://github.com': No such file or directory