我计划在我的项目中使用 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 密钥)以推送到远程存储库?