如何使用python库GitPython提交和推送文件

时间:2019-06-05 06:41:44

标签: python github gitpython

要求:

  • 从python脚本提交文件并将其推送到GitHub存储库。
  • 凭据应包含在脚本中。

问题:

  • 如果脚本中提供了凭据,则提交操作为 执行并引发以下错误,
Traceback (most recent call last):
  File "/home/amith/example.py", line 14, in <module>
    repo.index.add(folder_path)
AttributeError: 'Repository' object has no attribute 'index'
  • 如果脚本中提供了的凭据,则通过在终端上提供提交操作,提交操作将正常工作。

我需要将此脚本集成到应该从配置文件接受凭据的Django应用程序中。

我尝试了以下链接,但对我来说没有任何作用。 -link1 -link2 -link3

from git import Repo
from github import Github
from pdb import set_trace as bp

repo_dir = '--------'
repo = Repo(repo_dir)

# using username and password

g = Github("-----", "------")
folder_path = '----------'
commit_message = 'Add New file'
repo.index.add(folder_path)
repo.index.commit(commit_message)
origin = repo.remote('origin')
origin.push()

因此,我收到此错误“ AttributeError:'Repository'对象没有属性'index'”。

完全错误-

Traceback (most recent call last):
  File "/home/amith/example.py", line 14, in <module>
    repo.index.add(folder_path)
AttributeError: 'Repository' object has no attribute 'index'

0 个答案:

没有答案