Problem
Suppose you are working on a GitHub-hosted repository myproject. As your project evolves, you start wondering the original name is ambiguous or unclear to potential users or collaborators.
So, you’ve decided to rename myproject to assembled-kalmanfilter-coremodel.
▶ Current Status
- current repository url:
https://github.com/OhGoshGit/myproject.git - remote name:
origin
% git remote -v
origin https://github.com/OhGoshGit/myproject.git (fetch)
origin https://github.com/OhGoshGit/myproject.git (push)▶ ToBe
% git remote -v
origin https://github.com/OhGoshGit/assembled-kalmanfilter-coremodel.git (fetch)
origin https://github.com/OhGoshGit/assembled-kalmanfilter-coremodel.git (push)Solutions
When you rename a repository, all existing information, with the exception of project site URLs, is automatically redirected to the new name, including:
- Issues
- Wikis
- Stars
- Followers
However, it’s still a good idea to update any references.
Warning !
If you create a new repository under your account in the future, do not reuse the original name of the renamed repository. If you do, redirects to the renamed repository will no longer work.
▶ Steps
Log in to GitHub and navigate to the Repository
- Go to GitHub and log in to your account.
- Go to the repository you want to rename.
Access Repository Settings:
- On the repository’s main page, click the
Settingstab
- On the repository’s main page, click the
Edit the Repository Name:
- In the
Generalsection, you’ll see theRepository namefield. - Enter the new name for your repository in the text box.
- In the
Confirm the Change:
- Click
Rename
- Click
Update Your Local Repository:
- change an existing remote repository URL in your local repository by running
git remote set-urlcommand
# When you use HTTPS git remote set-url origin https://github.com/your-username/new-repository-name.git # When you use SSH git remote set-url origin git@github.com:your-username/new-repository-name.git- change an existing remote repository URL in your local repository by running
Confirmation
- Test pushing or pulling to ensure the updated remote URL works correctly:
git remote -v git pull origin mainnotify your collaborators
- If others are using the repository, notify them about the name change.
git remote set-url command
The git remote set-url command is used to update the URL of a remote repository in your local Git configuration. This is often necessary when the remote repository’s URL changes (e.g., due to renaming, migration, or switching protocols).
▶ Syntax
git remote set-url <remote-name> <new-url><remote-name>: The name of the remote (commonlyorigin)<new-url>: The new URL for the remote repository
The git remote set-url command only updates the URL; it does not create a new remote. If the remote name (e.g., origin) doesn’t exist, you’ll need to add it using git remote add first.
▶ Tips
If you’ve accidentally made a wrong <remote-name>, you can remove by the following command:
git remote rm <wrong-remote-name>