Go-github: How to commit to empty repository?

Created on 27 Dec 2018  路  6Comments  路  Source: google/go-github

I was trying to create new repo and then commit files to that repo.
Creating repo is ok but I got an error "409 Git Repository is empty.", when I try to commit file to that repo.
Can't we commit to new repo? Or is there any way to do empty commit by using go-github?

Most helpful comment

We need to clarify a few things here.

If you want to interact with GitHub via the GitHub Developers v3 API, then you will most likely want to use this package.

If, however, all you want to do is locally create a git repo and commit files to that repo from Go, then you have a couple options:

  • Call the git init, git add, git commit, git push, etc. CLI commands directly from Go using the exec package, or
  • Use a Git API client such as https://github.com/src-d/go-git for example.

If you do indeed want to interact with the GitHub Developers v3 API, then take a look at our examples directory for some hints.

If you still need help, then please post a short example of the code you are trying to run (without any access tokens, of course) and we will try and help you identify the problem and get it working.

All 6 comments

Hi @htetmyomyint :

Hope you are doing well !

If you question is generic and not related with this project/repo, then you can do a empty commit by below:
git commit --allow-empty -m 'Your commit message'

If you question is related with creating a copy of go-github repository and performing commits, then probably you need to do below set of steps:

  1. Click on Fork repo link on top right of home right of repo. This will fork/copy this repo under your profile. You can find this under your profile list of repositories.
  2. From terminal, you can run below command to get the repo on your local IDE. Please note, below are urls specific to my username. After forking, you can replace username(dreamer-89) with your username.
    go get github.com/dreamer-89/go-github
    OR
    git clone [email protected]:dreamer-89/go-github.git
    https://github.com/dreamer-89/go-github

For details on contributing on this repo, please check below:
https://github.com/google/go-github/blob/master/CONTRIBUTING.md

Please let me know if it was helpful and feel free to ask again.

@dreamer-89
I am sorry that my question is unclear. Actually, I want to write a program( by using go-github api ) that can create repo and commit files to that created repo. But I've got an error( 409 Git repository is empty ). So, I want to know how should I solve or I want to get reference links for solving the problem.

We need to clarify a few things here.

If you want to interact with GitHub via the GitHub Developers v3 API, then you will most likely want to use this package.

If, however, all you want to do is locally create a git repo and commit files to that repo from Go, then you have a couple options:

  • Call the git init, git add, git commit, git push, etc. CLI commands directly from Go using the exec package, or
  • Use a Git API client such as https://github.com/src-d/go-git for example.

If you do indeed want to interact with the GitHub Developers v3 API, then take a look at our examples directory for some hints.

If you still need help, then please post a short example of the code you are trying to run (without any access tokens, of course) and we will try and help you identify the problem and get it working.

@gmlewis
Thank you. Now I understand that I should set the required values (according to go-github's Repository struct) to get the desired result.

Hi i am facing isssue in github the repository is empty can anyone help me ..?
"We couldn鈥檛 access the repository Abbas798/site2. This could be because the repository is empty or disabled. "

@Abbas798 - please contact GitHub technical support to access your empty or disabled repo.

This repo is a Go client library to access the GitHub v3 API developed and maintained by volunteers.

Was this page helpful?
0 / 5 - 0 ratings