GitHub v3 API: How to create initial commit for my shiny new repository?

陌路散爱 提交于 2019-12-21 10:24:22

问题


GitHub API docs says:

Git DB API functions will return a 409 if the git repo for a Repository is empty or unavailable.

My POST on $repo/git/trees returns 409 indeed.

How do I create initial commit in the repository then? Do I have to force user to commit some useless junk manually, just for the sake of creating root commit?


回答1:


I emailed github support with the same issue and here is their response:

From: Rick (GitHub Staff)
Subject: Creating an initial commit using the v3 API

Currently, you can't add the initial commit through the API.  Thanks for the
feedback. I've added your suggestion to the Feature Request List™ for the team
to see.

As a workaround, depending on your use case, you may be able to create forks rather than new repos.




回答2:


Update September 28, 2012

According to this blogpost published on github blog, now it is possible to auto initialize a repository after creation.

Today we’ve made it easier to add commits to a repository via the GitHub API. Until now, you could create a repository, but you would need to initialize it locally via your Git client before adding any commits via the API.

Now you can optionally init a repository when it’s created by sending true for the auto_init parameter:

 curl -i -u pengwynn \
      -d '{"name": "create-repo-test", "auto_init": true}' \
      https://api.github.com/user/repos 

The resulting repository will have a README stub and an initial commit.



来源:https://stackoverflow.com/questions/9670604/github-v3-api-how-to-create-initial-commit-for-my-shiny-new-repository

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!