How do I rename a Git repository?
git mv
renames a file or directory in a repository. How do I rename the Git repository itself?
Solution 1:
There are various possible interpretations of what is meant by renaming a Git repository: the displayed name, the repository directory, or the remote repository name. Each requires different steps to rename.
Displayed Name
Rename the displayed name (for example, shown by gitweb
):
- Edit
.git/description
to contain the repository's name. - Save the file.
Repository Directory
Git does not reference the name of the directory containing the repository, as used by git clone master child
, so we can simply rename it:
- Open a command prompt (or file manager window).
- Change to the directory that contains the repository directory (i.e., do not go into the repository directory itself).
- Rename the directory (for example, using
mv
from the command line or the F2 hotkey from a GUI).
Remote Repository
Rename a remote repository as follows:
- Go to the remote host (for example, https://github.com/User/project).
- Follow the host's instructions to rename the project (will differ from host to host, but usually Settings is a good starting point).
- Go to your local repository directory (i.e., open a command prompt and change to the repository's directory).
- Determine the new URL (for example,
[email protected]:User/project-new.git
) -
Set the new URL using Git:
git remote set-url origin [email protected]:User/project-new.git
Solution 2:
A Git repository doesn't have a name. You can just rename the directory containing your worktree if you want.
Solution 3:
Rename PRJ0.git
to PROJ1.git
, then edit the URL variable located in the .git/config
file of your project.
Solution 4:
With Github As Your Remote
Renaming the Remote Repo on Github
Regarding the remote repository, if you are using Github or Github Enterprise as the server location for saving/distributing your repository remotely, you can simply rename the repository directly in the repo settings.
From the main repo page, the settings tab is on the right, and the repo name is the first item on the page:
Github will redirect requests to the new URL
One very nice feature in Github when you rename a repo, is that Github will save the old repo name and all the related URLs and redirect traffic to the new URLs. Since your username/org and repo name are a part of the URL, a rename will change the URL.
Since Github saves the old repo name and redirects requests to the new URLs, if anyone uses links based on the old repo name when trying to access issues, wiki, stars, or followers they will still arrive at the new location on the Github website. Github also redirects lower level Git commands like git clone
, git fetch
, etc.
More information is in the Github Help for Renaming a Repo
Renaming the Local Repo Name
As others have mentioned, the local "name" of your repo is typically considered to be the root folder/directory name, and you can change that, move, or copy the folder to any location and it will not affect the repo at all.
Git is designed to only worry about files inside the root folder.