git mv renames a file or directory in a repository. How do I rename the Git repository itself?
git mv renames a file or directory in a repository. How do I rename the Git repository itself?
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.
Rename the displayed name (for example, shown by gitweb):
.git/description to contain the repository's name.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:
mv from the command line or the F2 hotkey from a GUI).Rename a remote repository as follows:
git@github.com:User/project-new.git)Set the new URL using Git:
git remote set-url origin git@github.com:User/project-new.git
A Git repository doesn't have a name. You can just rename the directory containing your worktree if you want.
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:
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
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.
In a new repository, for instance, after a $ git init, the .git directory will contain the file .git/description.
Which looks like this:
Unnamed repository; edit this file 'description' to name the repository.
Editing this on the local repository will not change it on the remote.
If you are using GitLab or GitHub, then you can modify those files graphically.
Using GitLab
Go to your project Settings. There you can modify the name of the project and most importantly you can rename your repository (that's when you start getting in the danger section).
Once this is done, local clients configurations must be updated using
git remote set-url origin sshuser@gitlab-url:GROUP/new-project-name.git
If you meant renaming your repository, go to your repository and click "admin", then rename.
Once you see the red box warning you about some sky-fallingness and other things, go read this question.
It's ambiguous what you mean by "renaming a git repository itself", but one interpretation of that is changing the URL of a remote git repository.
git remote set-url origin url
https://www.commands.dev/workflows/change_url_of_remote_git_repository
I bookmarked ^ page, it tells me the command and allows me play around with the parameters. Super useful, IMO.
Have you try changing your project name in package.json and execute command git init to reinitialize the existing Git, instead?
Your existing Git history will still exist.
This is an extremely simple solution, though some may consider it "inelegant" or a "hack", and it belies my git inexpertise.
rm -r project-original-name).git clone https://github.com/User/project-new-nameNOTE: If another user of the repo doesn't follow these instructions, and just does a pull in the future, I have no idea what effect this will have.
Open git repository on browser, got to "Setttings", you can see rename button.
Input new "Repository Name" and click "Rename" button.
Server Side: mv oldName.git newName.git
Client Side: ./.git/config change [remote "origin"] | url to newName.git
This worked for me on Windows 10, via the command line:
git checkout <oldname>
git branch -m <newname>
From How To Rename a Local and Remote Git Branch
This was a local-only repository (not on any remotes).