How do I rename a GitHub repository via their API?

前端 未结 4 1629
隐瞒了意图╮
隐瞒了意图╮ 2020-12-16 04:19

Looking at the GitHub API reference at http://develop.github.com/p/repo.html, I see all sorts of good stuff, but I don\'t see any way to rename a repository through the API.

相关标签:
4条回答
  • 2020-12-16 04:21

    Create some variables for clarity:

    user=MyUserName
    pass=MyPassword
    newName='{"name": "NewNameForRepo"}'
    oldName="MyRepo"
    

    Then use curl to make the request:

    curl -u "$user:$pass" -X PATCH -d "$newName" https://api.github.com/repos/$user/$oldName
    
    0 讨论(0)
  • 2020-12-16 04:22

    This is possible through the Edit Repository GitHub API method, but here's the simplest example to do this with curl:

    curl \
     -H "Authorization: Token [token]" \
     -H "Content-Type:application/json" \
     -H "Accept: application/json" \
     -X PATCH \
     --data '{ "name": "new-repo-name" }' \
     https://api.github.com/repos/owner/old-repo-name
    
    0 讨论(0)
  • 2020-12-16 04:24

    Create a new repo, push to it and delete the old one ?

    0 讨论(0)
  • 2020-12-16 04:31

    Adding additional notes to what braitsch said already,

    If you are trying to rename a repository under an organization, add these variables:

    myToken='XXXX_Your_Personal_Access_Token_XXXX'
    myOrg="MyGithubOrg"
    newName='{"name": "NewNameForRepo"}'
    oldName="MyRepo"
    

    And, make a curl request like this:

    curl -H 'Authorization: token $myToken' -X PATCH -d "$newName" https://api.github.com/repos/$myOrg/$oldName 
    
    0 讨论(0)
提交回复
热议问题