问题
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