Skip to content

Instantly share code, notes, and snippets.

@navinpai
Created January 6, 2017 18:43
Show Gist options
  • Save navinpai/d5c65558a678904e3afebeb0a0060391 to your computer and use it in GitHub Desktop.
Save navinpai/d5c65558a678904e3afebeb0a0060391 to your computer and use it in GitHub Desktop.
Add Commit via PyGithub
import github
g = github.Github("username", "password")
repo = g.get_repo('username/reponame')
head_ref = repo.get_git_ref("heads/master")
latest_commit = gh_repo.get_git_commit(head_ref.object.sha)
base_tree = latest_commit.tree
new_tree = repo.create_git_tree([github.InputGitTreeElement(path="filename",mode='100644',type='blob',content="filecontent")],base_tree)
new_commit = repo.create_git_commit(message="commit message",parents=[latest_commit],tree=new_tree)
head_ref.edit(sha=new_commit.sha, force=False)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment