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

时间:2014-08-03 20:29:27

标签: 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.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:

最后一行之后没有留言。但是,如果我从命令行手动运行git push --porcelain origin,则会收到错误:

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

这是一个公平的错误。它是一个全新的存储库,我还没有完全配置。但是,我计划在多台机器上部署这个项目(并且能够推送),所以我更愿意通过GitPython自动完成。

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

1 个答案:

答案 0 :(得分:0)

您至少需要手动推送一次(即 git push -u origin ),以便您的本地仓库在第一次执行此操作后在远程端被识别,您将不会再次看到此问题

相关问题