Create Github repository from API

后端 未结 1 1221
终归单人心
终归单人心 2020-12-12 08:11

Please provide working code that creates a Github repository using the API.

I have tried different versions of the following:

curl \'https://api.gith         


        
相关标签:
1条回答
  • 2020-12-12 08:54

    The following works:

    (without variables)
    curl -H "Authorization: token abcdefghijklmnopqrstuvwxyz1234567890abcd" 
      --data '{"name":"name-foo"}' https://api.github.com/user/repos
    
    (with variables)
    NAME='name-foo'
    TOK='abcdefghijklmnopqrstuvwxyz1234567890abcd'
    BASE='https://api.github.com/'
    EXT='user/repos'
    URL=$BASE$EXT
    curl -H "Authorization: token $TOK" --data "{\"name\":\"$NAME\"}" $URL
    

    One can use personal access tokens instead of OAuth.

    The YOUR_TOKEN value in the "Authorization: token YOUR_TOKEN" section of the curl command can be obtained as follows.

    1. Upper right corner, click User
    2. Settings
    3. Personal Access Tokens
    4. For scopes, select Repos.
    5. Create New Token.

    For more details, click here and here.

    0 讨论(0)
提交回复
热议问题