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. Is there any way to do so?
Asked
Active
Viewed 6,223 times
5 Answers
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

braitsch
- 14,906
- 5
- 42
- 37
-
1I've confirmed that this works. I used OAuth2 token instead of `user:pass`. – Paul Annesley Apr 26 '12 at 08:05
-
More clarity: [`-X`](https://stackoverflow.com/a/8502004/1705829) is used to specify another request method besides PUT, GET,HEAD and POST, `patch` is used to modify a resource on the server partially. `-d` is for `POST`ing a key-value pair, see my link on the X flag. – Timo Mar 08 '22 at 11:11
-
Adding to @PaulAnnesley comment, you can do: `curl -u "$user:$token..` instead of `curl -u $user:$pw..` – Timo Mar 08 '22 at 11:14
4
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

Evandro Coan
- 8,560
- 11
- 83
- 144

Brendan Forster
- 2,548
- 1
- 24
- 32
0
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

Raktim Biswas
- 4,011
- 5
- 27
- 32
0
If we're using GitHub CLI:
gh alias set repo-rename 'api -X PATCH "repos/$1" -f name="$2"'
gh repo-rename username/oldreponame newreponame

Simon Allfrey
- 51
- 1
- 6
-3
Create a new repo, push to it and delete the old one ?

Stefan Näwe
- 3,040
- 1
- 18
- 19
-
-
1The create/push/delete solution kind of works, but the new repo would contain whatever I pushed from my local copy of the repo, so it wouldn't necessarily be a perfect copy of the old GitHub repo. Also, wouldn't I lose issues and wiki and stuff if I did that? – Ryan C. Thompson Jan 24 '11 at 19:45
-
Yes, you would lose issues and wiki. Maybe you want to ask Guthub's support team? – Stefan Näwe Jan 25 '11 at 08:19