Last active
January 24, 2020 15:08
-
-
Save mtboren/4d68fe0aca90d89bdbd4526b24a22a8b to your computer and use it in GitHub Desktop.
Rename a GitHub repository using the PowerShellForGitHub PowerShell module
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## some PowerShell snippets to illustrating the forking- and subsequent renaming of a GitHub repository | |
# uses Invoke-GHRestMethod for the rename operation, as there is not yet a higher level cmdlet for dealing with repo renames | |
## import the module, of course | |
Import-Module PowerShellForGitHub | |
## fork some source repo; forks under current GitHub user configured via Set-GitHubAuthentication | |
New-GitHubRepositoryFork -Uri https://github.com/aws-quickstart/quickstart-dotnet-serverless-cicd -OutVariable oNewRepo | |
## rename the forked repo in user's GH account, prefixing "fork_" so the world clearly knows that its was forked from elsewhere just by glancing at name | |
# UriFragment here is something like "repos/owner/repoName" | |
Invoke-GHRestMethod -Method Patch -UriFragment ("repos{0}" -f ([System.Uri]($oNewRepo.html_url)).AbsolutePath) -Body (@{name = "fork_{0}" -f ($oNewRepo.name)} | ConvertTo-Json) -Verbose -OutVariable oUpdatedRepoFork | |
## would expect/desire the ability to rename a repo with a "native" cmdlet, maybe something like: | |
# $oNewRepo | Foreach-Object {$_ | Rename-GitHubRepository -NewName "fork_$($_.name)"} | |
## hurray, this renamed the forked repo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment