How do I push new files to GitHub?
A very similar question who's code I was able to modify to make multiple file pushes to github via python:
import base64
from github import Github
from github import InputGitTreeElement
user = "GithubUsername"
password = "*********"
g = Github(user,password)
repo = g.get_user().get_repo('git-test') # repo name
file_list = [
'C:\UsersjesseDropboxSwell-Forecastgit-testindex.html',
'C:\UsersjesseDropboxSwell-Forecastgit-testmargin_table.html'
]
file_names = [
'index.html',
'margin_table.html'
]
commit_message = 'python commit'
master_ref = repo.get_git_ref('heads/master')
master_sha = master_ref.object.sha
base_tree = repo.get_git_tree(master_sha)
element_list = list()
for i, entry in enumerate(file_list):
with open(entry) as input_file:
data = input_file.read()
if entry.endswith('.png'): # images must be encoded
data = base64.b64encode(data)
element = InputGitTreeElement(file_names[i], '100644', 'blob', data)
element_list.append(element)
tree = repo.create_git_tree(element_list, base_tree)
parent = repo.get_git_commit(master_sha)
commit = repo.create_git_commit(commit_message, tree, [parent])
master_ref.edit(commit.sha)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…