Search code examples
githubgithub-api

How to bulk migrate github repos from one organization to another?


Similar to How to clone all repos at once from GitHub?, I wonder if there is a clean, GitHub CLI set of commands or shell script, to take the local cloned repos and then upload them to another.

My specific use case was to grab backups of my git repos from a school organization, and want to keep a copy on general GitHub. Though this would generally apply to migration between hosts, like GitLab to GitHub, or between hosted orgs.

The workflow if I was doing it manually would be similar to the answer of Migrate from github enterprise to github.com one would want to preserve or set the access of new repos (e.g. keep them private). Would just rather get the starting point of a script, than do these steps manually a couple dozen times.


Solution

  • Such a script could use the GitHub CLI gh command.
    Specifically, the gh repo create:

    # create a remote repository from the current directory
    gh repo create my-project --private --source=. --remote=upstream --push
    

    In one command, from one of your local Git repository, you create a GitHub my-project repository, private, and push any local history to said new repository.

    You can loop and repeat that for each if your local repositories.