You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Add readme and .gitignore file in repository creation #2330
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.
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?
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.
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. 😄
Activity
gmlewis commentedon Apr 11, 2022
Maybe you could use https://github.com/go-git/go-git to push the files to the new repo?
yuseferi commentedon Apr 11, 2022
@gmlewis thanks for your attention, but does GitHub commit when it adds
.gitignoreandREADME.mdfile when it generates a new project?gmlewis commentedon Apr 11, 2022
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.
yuseferi commentedon Apr 11, 2022
@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?
gmlewis commentedon Apr 11, 2022
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?
yuseferi commentedon Apr 11, 2022
@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?
gmlewis commentedon Apr 11, 2022
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.
yuseferi commentedon Apr 11, 2022
@gmlewis after some investigation on the API https://docs.github.com/en/rest/reference/repos#contents I found
auto_initPass true to create an initial commit with empty README.and finally with passing
truetoAutoInitmy issue is fixed!thank your attention
gmlewis commentedon Apr 11, 2022
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. 😄
Add example to create repository with an initial commit with empty RE…
Add example to create repository with an initial commit with empty RE…