Skip to content

Allow gh to transfer ownership of repo from one org to another #5292

Open

Description

@scott-doyland-burrows

I would like to be able to use the gh CLI to transfer ownership from one org to another, something such as:

gh repo transfer-ownership source-org/source-repo target-org/target-repo

Sometimes the repo needs to be made public to transfer, and then set back to private, I think this is when 2FA is switched on.

If the command could handle all things required to transfer the repo, then it'd be great, eg:

set to public on source org and then back to private on target org
rename on target org
add to a team on target org
whatever else all done with just the one command, to save scripting multiple commands to achieve the transfer.

Thanks

Activity

  1. mislav commented on Mar 10, 2022

    @mislav
    Contributor

    In the meantime you can do:

    gh api repos/{owner}/{repo}/transfer -f new_owner=NEWOWNER
    

    See https://docs.github.com/en/rest/reference/repos#transfer-a-repository

    Sometimes the repo needs to be made public to transfer, and then set back to private, I think this is when 2FA is switched on.

    Bizarre! I would not suggest that anyone ever does this. Private repos that are intentionally private should never be made public, not even for a second.

  2. scott-doyland-burrows commented on Mar 10, 2022

    @scott-doyland-burrows
    Author

    Thanks for the CLI command - I tried it and it works fine.

  3. jsoref commented on May 11, 2022

    @jsoref
    Contributor

    Fwiw, I'd argue that the command should be gh repo transfer {<[org/]repo> | <url>} <destination-repo> to match gh issue transfer {<number> | <url>} <destination-repo>.

  4. jf-delineate commented on Jun 20, 2022

    @jf-delineate
    Contributor

    @mislav are you ok with @jsoref suggestion of the gh repo transfer {<[org/]repo> | <url>} <destination-repo> syntax? I'd be happy to take this one on.

  5. mislav commented on Jun 21, 2022

    @mislav
    Contributor

    @jf-delineate That looks good! I also think that there should be an explicit confirmation step (skippable with --confirm flag).

  6. rwp0 commented on Feb 13, 2023

    @rwp0

    In the meantime you can do:

    gh api repos/{owner}/{repo}/transfer -f new_owner=NEWOWNER
    

    See https://docs.github.com/en/rest/reference/repos#transfer-a-repository

    Sometimes the repo needs to be made public to transfer, and then set back to private, I think this is when 2FA is switched on.

    Bizarre! I would not suggest that anyone ever does this. Private repos that are intentionally private should never be made public, not even for a second.

    Thanks.

    Can set transfer alias, with arguments, as follows:

    gh alias set transfer 'api repos/$1/transfer -f new_owner=$2'

    I've created a snippet to help myself remembering that:
    https://gist.github.com/rwp0/122330fa414877778dc6a20f183e1bcb

    Would very much like to drop my alias when repo transfer is out.

  7. benjlevesque commented on Feb 14, 2024

    @benjlevesque
    Contributor

    I've been using gh api to transfer repos, as recommended by @mislav (thanks 🙏) and it works great.

    The repo is transfered, but the remotes are not updated. It's fine to pull & push, as Github handles that, but it breaks a few gh features. For instance, running gh pr create will cause Head ref must be a branch, not all refs are readable.

    I see these options:
    1/ have the transfer command update the git remotes. This one is great for the person who runs the command, but not so much for other contributors to that repo, who will also need to update their remotes...
    2/ make gh resilient, the same way Github is, to repo transfer (meaning: without changing the remotes)
    3/ detect that the repo has been migrated and prompt user to update remote (or do it automatically)

    I haven't digged a lot into the feasability of 2/ and 3/, is there a reponse header or specific status that could be used?

  8. unitof commented on Feb 20, 2025

    @unitof

    @jf-delineate Were you able to make progress on this? No worries if not, or still tinkering!

    One suggestion: I would like if the current repo could be auto-detected based on the CWD if omitted, as with many other gh repo commands. Makes it easier to bulk transfer a number of local repos to the same receiving team, with the same command.

  9. iamazeem commented on Mar 6, 2025

    @iamazeem
    Contributor

    @cli/code-reviewers: Please add its Acceptance Criteria. Thanks!

    API: https://docs.github.com/en/rest/repos/repos?apiVersion=2022-11-28#transfer-a-repository

    From the initial investigation, looks like it would be similar to gh repo rename command.
    See: https://github.com/cli/cli/blob/trunk/pkg/cmd/repo/rename/rename.go

    Tentative command invocations:

    # Transfer current repo with the same name
    $ gh repo transfer NEW_OWNER_NAME
    
    # Transfer current repo with a new name
    $ gh repo transfer NEW_OWNER_NAME/NEW_REPO_NAME
    
    # Transfer some other repo with the same name
    $ gh repo transfer --repo OLD_OWNER_NAME/REPO NEW_OWNER_NAME
    
    # Transfer some other repo with a new name
    $ gh repo transfer --repo OLD_OWNER_NAME/REPO NEW_OWNER_NAME/NEW_REPO_NAME
    
    ---
    
    ## in addition to above, when OWNER is an org, add support for --teams-ids <csv-team-ids>
    $ gh repo transfer NEW_OWNER_NAME --team-ids 1,2,3
  10. changed the title [-]Allow gh cli to transfer ownership of repo from one org to another[/-] [+]Allow `gh` to transfer ownership of repo from one org to another[/+] on Apr 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementa request to improve CLIgh-reporelating to the gh repo commandpitchpitched internally for prioritisation

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions