Rename a GitHub Repository Safely with gh repo rename
You will finish with a controlled way to rename a GitHub repository from the shell, check that you selected the intended target, and update local Git remotes afterwards. The examples use GitHub CLI 2.87.3, installed here as Ubuntu package gh 2.45.0-1ubuntu0.3+esm3.
The route
Jump straight to the step you need, or tick off Done means at the end.
Allow about ten minutes for the rename and checks. You need gh, an authenticated GitHub CLI session with administrator access to the repository, and a local clone if you want to update its remote. No command in this guide needs sudo.
1. Check the installed command
Read the local command help before changing anything. This is an ordinary, read-only check:
$ gh --version
gh version 2.87.3 (2026-02-23)
$ gh repo rename --help
Rename a GitHub repository.
USAGE
gh repo rename [<new-name>] [flags]
The command takes one optional new repository name. The installed manual documents two useful flags: --repo selects a repository in [HOST/]OWNER/REPO form, and --yes skips the confirmation prompt. The new name is the repository name only, without the owner.
Checkpoint: make sure the version and syntax match the command you are about to run. If this machine uses a different release, run its help again and treat that output as authoritative.
2. Confirm the repository and the new name
A rename is a remote state change. Write down the old full name and the exact new name before opening the prompt:
$ OLD_REPO='OWNER/old-repository'
$ NEW_NAME='new-repository'
$ printf 'Will rename %s to %s/%s\n' "$OLD_REPO" "${OLD_REPO%%/*}" "$NEW_NAME"
Will rename OWNER/old-repository to OWNER/new-repository
Replace both placeholder values with real values. Keep NEW_NAME as a simple repository name, not OWNER/new-repository. The command does not use an owner in the new-name argument.
If you are standing inside the local clone of the repository, the shortest form targets the current repository:
$ gh repo rename "$NEW_NAME"
? Rename repository OWNER/old-repository to new-repository? Yes
Do not answer the prompt until the displayed owner and old repository name are correct. A typo in the destination is a change to the wrong remote, not a local filename mistake.
3. Select another repository explicitly
Use --repo when your current directory is unrelated, or when you want the target to be obvious in a script review:
$ gh repo rename --repo "$OLD_REPO" "$NEW_NAME"
? Rename repository OWNER/old-repository to new-repository? Yes
The short spelling is gh repo rename -R OWNER/old-repository new-repository. For a GitHub Enterprise host, include the host, for example ghe.example/OWNER/old-repository. The owner stays in the selector; it is not copied into the new-name argument.
Keep the confirmation prompt for an interactive one-off operation. --yes is useful only after the target has been independently checked in automation:
$ gh repo rename --repo "$OLD_REPO" "$NEW_NAME" --yes
Warning: --yes removes the last human check immediately before the rename. Do not combine it with an unreviewed value from an issue, pull request or other external input.
4. Verify the new repository
After a successful rename, ask GitHub CLI to view the new repository. This confirms the destination rather than relying only on the absence of an error:
$ NEW_REPO="${OLD_REPO%%/*}/$NEW_NAME"
$ gh repo view "$NEW_REPO" --json nameWithOwner --jq .nameWithOwner
OWNER/new-repository
The command should print the expected owner and new name. If it fails, check authentication and the spelling of NEW_REPO; do not repeat the rename with another guessed name.
5. Update a local clone
GitHub redirects normal web and Git operations from the old repository location, but a local remote should still be updated so future commands show the correct destination. Inspect the current remote first:
$ git remote -v
origin [email protected]:OWNER/old-repository.git (fetch)
origin [email protected]:OWNER/old-repository.git (push)
Then replace only the remote URL with the new one. Run this from the clone whose origin you inspected:
$ git remote set-url origin "[email protected]/${NEW_REPO}.git"
$ git remote -v
origin [email protected]:OWNER/new-repository.git (fetch)
origin [email protected]:OWNER/new-repository.git (push)
If your clone uses HTTPS, preserve that style instead:
$ git remote set-url origin "https://github.com/${NEW_REPO}.git"
This local edit is reversible. Before changing it, save the old URL with git remote get-url origin. To undo the local edit, run git remote set-url origin OLD_URL, replacing OLD_URL with that saved value. This does not rename the GitHub repository back.
6. Check dependent links and automation
GitHub preserves redirects for many repository pages, issues, stars, and ordinary Git clone, fetch and push operations. It does not redirect calls to an action hosted by a renamed repository. Search workflows, documentation, deployment configuration and package metadata for the old owner/name and update them deliberately.
$ rg -n --hidden --glob '!.git' 'OWNER/old-repository|old-repository' .
Pay particular attention to reusable workflow references such as OWNER/old-repository/.github/workflows/..., badges, container image names and scripts that construct a URL. A repository rename is not a transfer of ownership; moving it to another user or organisation requires additional GitHub steps outside this command.
There is no local undo flag in gh repo rename. To reverse the remote change, run the same command with the original repository name after checking the target and dependencies again. Treat that as another deliberate remote change, not as a routine rollback.
Done means
- The installed
ghversion and local help matched the syntax used. - The owner, old name and new name were checked before confirmation.
gh repo viewreports the expected new repository name.- Each affected clone has an
originURL using the new name. - Workflows, action references, documentation and deployment links no longer depend on the old name where redirects are not enough.
- You have saved the old remote URL and understand that reversing the remote rename is a second rename operation.