Skip to content

Add readme and .gitignore file in repository creation #2330

Closed

Description

@yuseferi

Hi there,
I'm using something similar to https://github.com/google/go-github/blob/master/example/newrepo/main.go
to create a new repository.
All works well, I'm looking for a way when I'm creating a new repository add a readme.md and .gitignore file to it. something like what the GitHub web interface does when you create a new repository.

if somebody has done something similar or knows how can I achieve this I really appreciate it.

Thanks in advance!

Activity

  1. gmlewis commented on Apr 11, 2022

    @gmlewis
    Collaborator

    Maybe you could use https://github.com/go-git/go-git to push the files to the new repo?

  2. yuseferi commented on Apr 11, 2022

    @yuseferi
    ContributorAuthor

    @gmlewis thanks for your attention, but does GitHub commit when it adds .gitignore and README.md file when it generates a new project?

  3. gmlewis commented on Apr 11, 2022

    @gmlewis
    Collaborator

    You could also investigate using a repo template: https://docs.github.com/en/github-ae@latest/repositories/creating-and-managing-repositories/creating-a-repository-from-a-template
    But I have not done this myself, so all of this is speculation at this point. Maybe someone else has done this and they can comment.

  4. yuseferi commented on Apr 11, 2022

    @yuseferi
    ContributorAuthor

    @gmlewis thanks for the quick reply.
    no, I don't want to the template solution.
    I'm wondering why this Github repository could do commit what is the benefit to use https://github.com/go-git/go-git ?
    section question: does it support access to a private repository?
    I found this https://github.com/go-git/go-git/blob/8884a203d3798a9bc50f54e98582cb5758b4f5ee/_examples/clone/auth/basic/access_token/main.go but looks like username shouldn't be empty!

    I'm getting my token here https://github.com/google/go-github/blob/master/example/newrepo/main.go#L31, do you know how can I commit with go-github?

  5. gmlewis commented on Apr 11, 2022

    @gmlewis
    Collaborator

    Let me clarify a little bit.

    This repo is a Go client for the GitHub v3 Developer API.
    As a result, this repo can only do things that the official API can do.

    If you can find the functionality somewhere in those docs that I linked, then this repo should be able to do it.

    However, I don't remember seeing anything in the API that will allow you to commit files to the repo.

    This is why I recommended the above alternatives.

    Does that make sense, or am I not understanding correctly?

  6. yuseferi commented on Apr 11, 2022

    @yuseferi
    ContributorAuthor

    @gmlewis yup. great explanation :)

    Actually, the initial question was how can I do what these boxes do with go-github api?
    because it creates a readme file in the repository creation. maybe there is an option to achieve this in the go-GitHub package?

    eCreate_a_New_Repository

  7. gmlewis commented on Apr 11, 2022

    @gmlewis
    Collaborator

    Not that I'm aware of. Please search through the (linked above) official GitHub v3 API documentation to see if it is possible, but as far as I know, it is not. Sorry.

  8. yuseferi commented on Apr 11, 2022

    @yuseferi
    ContributorAuthor

    @gmlewis after some investigation on the API https://docs.github.com/en/rest/reference/repos#contents I found auto_init
    Pass true to create an initial commit with empty README.

    and finally with passing true to AutoInit my issue is fixed!
    thank your attention

  9. gmlewis commented on Apr 11, 2022

    @gmlewis
    Collaborator

    Awesome, @yuseferi ! I'm really glad you found it, and I apologize for not knowing the answer.
    Thank you, also, for reporting back so that others will hopefully be able to find this solution more easily than having to deal with me. 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions