git mv
renames a file or directory in a repository. How do I rename the Git repository itself?

- 30,738
- 21
- 105
- 131

- 12,300
- 15
- 49
- 79
-
6Your question is fine. Git has repositories and they can contain projects like Eclipse projects if you decide to place your project in a git repository. If that is what you were wanting then see how to do so in the anwswer below. – Danny Remington - OMS May 14 '13 at 19:39
-
5`git` itself has no provision to specify the repository name. The root directory name is the *single source of truth* pertaining to repository name. The `.git/description` file though is used only by some applications like `Gitweb` – Ujjwal Singh Jun 05 '16 at 17:36
21 Answers
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
Typically (with exceptions for worktrees and submodules explained below), Git does not reference the name of the directory containing the repository, so we can simply rename or move 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).
Moving a repository that has worktrees
If you have created worktrees using the git worktree
subcommands from the repository that is to be renamed, then each worktree directory will contain a .git
file that contains
gitdir: {full-path-to-parent-repository}/.git/worktrees/{worktree-name}
So if you move the location of the parent repository, for each such worktree you will also need to edit its .git
file to change the parent path.
Moving a directory that is a worktree
Use the git worktree move
command from the parent repository.
Moving a repository that has submodules
Similarly to the worktree case, the submodule directory has a .git
file pointing to its parent. The parent also has a .git/modules/{submodule}/config
file which may contain absolute paths that need to be edited. See also this question.
Renaming a submodule
Use git mv
as discussed in this answer.
Corner cases involving both submodules and worktrees
Don't do that. If you must, read the docs for git worktree repair
and probably also the docs for submodules to understand how they are implemented.
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,
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

- 2,264
- 22
- 14

- 41,819
- 10
- 94
- 108
-
3On the second case, what happens to whomever already cloned the repository? – Frederico Schardong Jul 29 '14 at 21:13
-
3Nothing bad. They retain the original name, but their remote is now wrong: if they want to pull updates they need to connect to the new name. If both you and they are synching or a central repository it will retain the original name and everything will continue to work – Alex Brown Jan 17 '15 at 19:45
-
24Note that the assertion "git does not reference this directory name" in the second case is wrong if you use submodules: git uses an absolute path to refer to submodules, so renaming your repository directory will break submodules. See https://stackoverflow.com/questions/10144149/git-status-returns-fatal-not-a-git-repository-but-git-exists-and-head-has-prop – Edward Jul 10 '17 at 09:23
-
I am using the GitHub for Windows GUI, and I did not have to change the .git/description file (I don't have one). The displayed name in the GUI changed after I did the last step of resetting the origin. – Joe Ernst Aug 31 '17 at 18:31
-
-
4I have relied on this note a few times. It is correct and it is good. However, I have always had to do a debug step when I got the message "fatal: Could not read from remote repository." --- The solution is that I rely on a public key to access GitHub. It is embedded in a hostname. --- Instead of "git@github.com:User/project-new.git", I need to use, "git@HOSTNAME:User/project-new.git". HOSTNAME is a reference in my .ssh/config file. --- (Now if only I remember to read this note next time. Glory awaits.) – tqwhite Feb 07 '19 at 16:43
-
7People keep mentioning .git/description, but with no mention of what change you actually put in there to rename the repo – Programmer Unextraordinair Feb 15 '19 at 17:48
-
If your project runs in a virtual environment you most probably need to delete it and re-create it from scratch (using a tool like [poetry](https://python-poetry.org/) does help then). – zezollo Jul 21 '20 at 13:03
-
Via consensus, it would be seem that this answer is correct and thorough. However, could you clarify one thing for me? If I want to "totally rename" my Git repository, should I follow the directions of all three interpretations? Or are one or two of the procedures already accomplished by following the third one? – mannyglover Feb 07 '21 at 01:55
-
Let's suppose you owned a software product called MegaBot. Marketing calls and says you have to call it ZipFix, everywhere! In most cases you would follow interpretations 2 and 3 to expunge "MegaBot" from the name of the repo. – Alex Brown May 04 '21 at 05:33
-
@tqwhite Remember to change the name of the remote repository in the config file otherwise fetch will fail (if you changed the name of the remote repo) – David Jul 29 '21 at 13:03
-
Keep in mind this about set-url https://stackoverflow.com/questions/41876631/changing-git-remote-url-updates-fetch-but-not-push – user2928048 Aug 22 '22 at 18:10
-
When renaming remote repository I was using the https instead of git@ : git remote set-url origin https://YOUR_NAME@bitbucket.org/YOUR_PROJECT_DIR/REPO_NAME.git – Sander van den Oord Sep 06 '22 at 08:53
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.

- 9,804
- 5
- 52
- 92
-
"if anyone uses links based on the old repo name ... they will still arrive at the new location on the Github website". Yes, there is such a feature. The same thing is valid for BitBucket: https://community.atlassian.com/t5/Bitbucket-questions/Bitbucket-old-ssh-URL-doesnt-change-after-renaming-the/qaq-p/1124814. It would be nice to know how to destroy completely any references to the old name, because it my understanding it is not renaming, but copying. Would be nice to know the correct procedure for the full rename (with destroying of all old stuff). – Alexander Samoylov Feb 27 '20 at 12:31
-
@AlexanderSamoylov I'm just guessing here, but I sincerely doubt anything is saved in the old format. Github should just be keeping the old archive name reserved and redirecting any traffic that comes in on the old archive name to the new archive name. i.e. `https://github.com/oldrepo/some_path` will just redirect to `https://github.com/newrepo/some_path`, where everything has been moved to. The only downside should be that the old repo name is permanently reserved so it can't be reused (also good to avoid people that have saved the old url accessing it). – LightCC Jun 08 '20 at 18:34
A Git repository doesn't have a name. You can just rename the directory containing your worktree if you want.

- 30,738
- 21
- 105
- 131

- 24,771
- 4
- 91
- 98
-
9Yes, a git repo have a name. I got this error after renaming: `$ git status fatal: Not a git repository: C:/xxx/.git/xxx fatal: git status --porcelain failed` – Sawny Jun 17 '12 at 13:19
-
23You said that a git repo dosen't have name, but that's not true. If you use submoduels and just rename the folder you will get errors from git. See http://stackoverflow.com/questions/9878860/how-can-i-rename-a-git-repository-with-submodules?lq=1 – Sawny Jun 18 '12 at 08:12
-
8Okay, a submodule's path within a git repository matters. It's true but not relevant to this particular question. – Tobu Jun 19 '12 at 19:00
-
5Of course repositories have a name. See below how to change it. – Danny Remington - OMS May 14 '13 at 19:37
-
For me, emacs-git breaks with a rename. I'm guessing it (incorrectly) assumes repository name is identical to working tree directory name. – BaseZen Sep 18 '16 at 19:07
-
Actually, involuntary upgrade of Xcode to version 8 broke *all* development tools, including whatever emacs / git.el depends on. So the internal "git-call-process" that starts up M-x git-status returned **Agreeing to the Xcode/iOS license requires admin privileges, please re-run as root via sudo.** Eff you very very very much Apple. – BaseZen Sep 18 '16 at 19:30
Rename PRJ0.git
to PROJ1.git
, then edit the URL variable located in the .git/config
file of your project.

- 158,662
- 42
- 215
- 303

- 191
- 2
- 2
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

- 30,738
- 21
- 105
- 131

- 6,100
- 6
- 41
- 47
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.

- 30,738
- 21
- 105
- 131

- 2,009
- 19
- 14
To rename any repository of your GitHub account:
- Go to that particular repository which you want to rename
- Navigate to the settings tab
- There, in the repository name section, type the new name you want to put and click Rename

- 30,738
- 21
- 105
- 131

- 757
- 7
- 16
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.

- 30,738
- 21
- 105
- 131

- 6,991
- 7
- 42
- 63
-
14Might help others to note that this is a Github-specific suggestion, and won't apply to Git in general. – founddrama Oct 25 '12 at 01:38
-
1as of January 2013, the github instructions should now be: (be logged in to github), go to your repo, then go to "Settings" >> "Options" and look for a Rename button there. Regarding the red warnings about bad things happening, Droogans link to the other s.o. question is still highly recommended. – pestophagous Jan 06 '13 at 19:41
If you are in Eclipse and have installed Egit then you can rename the repository that contains a project by doing the following:
1) In Eclipse: Close all projects that are in the repository.
2) In the file system: Locate the directory/folder that contains the repository.
3) In the file system: Rename the directory/folder that contains the repository.
4) In the file system: Open the directory/folder that contains the repository and rename the project directory/folder of any project you intend to rename so that it will match the new name of the project. (This is not required but it gives consistency between the project name in Eclipse and the project directory/folder in the repository.)
5) In Eclipse: Delete all projects that are in the repository but be sure to NOT check the 'Delete the contents from the file system' checkbox. (The project should no longer contain the correct location of the contents of the file system so the data could not be deleted in any case but it is better to be safe than sorry.)
6) In Eclipse: From the Menu select the File|Import... option.
7) In Eclipse: In dialog box open the 'Git' folder, select 'Projects from Git' and click 'Next'.
8) In Eclipse: In dialog box select 'Local' and click 'Next'.
9) In Eclipse: In dialog box click the 'Add...' button.
10) In Eclipse: In dialog box make sure the check box next to the repository is checked and click 'Finish'.
11) In Eclipse: In dialog box select the repository and click 'Next'.
12) In Eclipse: In dialog box select the 'Import existing projects' radio button, select the "Working Directory" and click 'Next'.
13) In Eclipse: In dialog box check the check box next to the projects you want to work on and click 'Finish'.
14) In Eclipse: Rename any the projects that are in the repository if so desired. (For consistency between Eclipse and the file system give them the same name as the project directory/folder inside the repository directory/folder.)

- 5,244
- 4
- 32
- 21
-
1+1 (amused and not surprised by 14 steps required for this in Eclipse, especially the 'if you have installed Egit', entailing a few dozen more steps...) – Jack Wasey Mar 22 '20 at 09:23
On the server side, just rename the repository with the mv command as usual:
mv oldName.git newName.git
Then on the client side, change the value of the
[remote "origin"]
URL into the new one:url=example.com/newName.git
It worked for me.

- 30,738
- 21
- 105
- 131

- 179
- 1
- 2
- 8
Git itself has no provision to specify the repository name. The root directory's name is the single source of truth pertaining to the repository name.
The .git/description
though is used only by some applications, like GitWeb.

- 30,738
- 21
- 105
- 131

- 4,908
- 4
- 37
- 54
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.

- 63
- 1
- 5
-
And for reference, if you want to find out what your current remote url is, use `git remote -v`. I found this useful to make sure I got the right format for setting the new url – Paul Masri-Stone Feb 08 '23 at 10:16
For Amazon AWS codecommit
users,
aws codecommit update-repository-name --old-name MyDemoRepo --new-name MyRenamedDemoRepo
Reference: here

- 30,738
- 21
- 105
- 131

- 2,919
- 1
- 17
- 27
To be simple, just remove that Eclipse Project (not choose content on disk), then re-import the project again.
Eclipse will identify the project connected to Git and put it in Git perspective view.
It works like a charm.

- 39
- 1
-
6
-
Is this answer a comment for [Danny Remington - OMS's answer](https://stackoverflow.com/questions/2041993/how-do-i-rename-a-git-repository/16551409#16551409)? – Peter Mortensen Oct 08 '19 at 15:55
- Go to the remote host (e.g., https://github.com/<User> ).
- Open repository
- Click tab Settings.
- Rename under Repository name (and press button Rename).

- 514
- 1
- 9
- 14
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.

- 2,718
- 1
- 14
- 10
This is an extremely simple solution, though some may consider it "inelegant" or a "hack", and it belies my git inexpertise.
- Verify that your local repo has everything committed and pushed (to remote origin).
- Go to the website of the remote host (for example, https://github.com/User/project-original-name). Follow the host's instructions to rename the repo (will differ from host to host, but usually Settings is a good starting point). (For the purposes of this guide, suppose you renamed your repo to "project-new-name".)
- Locally remove your whole repo (e.g.,
rm -r project-original-name
). - Do a "fresh checkout":
git clone https://github.com/User/project-new-name
NOTE: 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.

- 2,139
- 14
- 18
Open git repository on browser, got to "Setttings", you can see rename button.
Input new "Repository Name" and click "Rename" button.

- 149
- 6
-
You also need to set the new URL-Path otherwise the URL will keep containing the old name. – LC117 May 10 '21 at 07:14
Server Side: mv oldName.git newName.git
Client Side: ./.git/config change [remote "origin"] | url to newName.git

- 170
- 1
- 6
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).

- 30,738
- 21
- 105
- 131

- 1,073
- 1
- 9
- 24