2

I'm trying to use Go-Github to create a text file and push it into a remote branch but I'm totally confused on how to do it.

I'm able to get a listing of repositories with my client org

repos, _, err := client.Repositories.ListByOrg("MyOrg", nil)

I'm able to use that and get a remote branch

branch, resp, err := client.Repositories.GetBranch("MyOrg", "MyRepository", "MyBranch")

but for the life of me I'm unable to figure out how to commit a file (or files) in my local branch and push the commit to the remote branch.

Thanks for any help that anyone can give.

Community
  • 1
  • 1
Andrew
  • 21
  • 2
  • 1
    You don't, you use git for that. The GitHub API has nothing to do with your local repositories. – JimB Oct 23 '14 at 21:26

1 Answers1

0

You would need a different library to (in your local repo):

  • add a remote referencing your GitHub repo
  • fetch the remote branches
  • push your own branch.

See "git library for Go", like the libgit2/git2go project (and its push test).

push, err := remote.NewPush()
checkFatal(t, err)
err = push.AddRefspec("refs/heads/master")
checkFatal(t, err)
err = push.Finish()
checkFatal(t, err)
Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250