You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Allow gh to transfer ownership of repo from one org to another #5292
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.
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.
Reacted by Rui Chen, canuckjacq, Scott Doyland, imcb, Chad, Elvin Aslanov, Cuong Tran, Johannes Grumböck, jonnyhotchkiss, Garegin SeMerjyan and 17 more
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 aliasset transfer 'api repos/$1/transfer -f new_owner=$2'
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?
@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.
# 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
Reacted by Christophe Colombier, Jacob Ford and Andrii Oriekhov
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
Activity
mislav commentedon Mar 10, 2022
In the meantime you can do:
See https://docs.github.com/en/rest/reference/repos#transfer-a-repository
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.
scott-doyland-burrows commentedon Mar 10, 2022
Thanks for the CLI command - I tried it and it works fine.
jsoref commentedon May 11, 2022
Fwiw, I'd argue that the command should be
gh repo transfer {<[org/]repo> | <url>} <destination-repo>to matchgh issue transfer {<number> | <url>} <destination-repo>.jf-delineate commentedon Jun 20, 2022
@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.mislav commentedon Jun 21, 2022
@jf-delineate That looks good! I also think that there should be an explicit confirmation step (skippable with
--confirmflag).rwp0 commentedon Feb 13, 2023
Thanks.
Can set
transferalias, with arguments, as follows: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 transferis out.benjlevesque commentedon Feb 14, 2024
I've been using
gh apito 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
ghfeatures. For instance, runninggh pr createwill causeHead ref must be a branch, not all refs are readable.I see these options:
1/ have the
transfercommand 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
ghresilient, 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?
unitof commentedon Feb 20, 2025
@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 repocommands. Makes it easier to bulk transfer a number of local repos to the same receiving team, with the same command.iamazeem commentedon Mar 6, 2025
@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 renamecommand.See: https://github.com/cli/cli/blob/trunk/pkg/cmd/repo/rename/rename.go
Tentative command invocations:
[-]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[/+]