How do I rename a Git repository?

Viewed 473103

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

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):

  1. Edit .git/description to contain the repository's name.
  2. 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:

  1. Open a command prompt (or file manager window).
  2. Change to the directory that contains the repository directory (i.e., do not go into the repository directory itself).
  3. 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:

  1. Go to the remote host (for example, https://github.com/User/project).
  2. Follow the host's instructions to rename the project (will differ from host to host, but usually Settings is a good starting point).
  3. Go to your local repository directory (i.e., open a command prompt and change to the repository's directory).
  4. Determine the new URL (for example, git@github.com:User/project-new.git)
  5. 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.

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:

enter image description here

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.

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.

The main name change is here (img 1), but also change readme.md (img 2)

enter image description here

enter image description here

  1. Go to the remote host (e.g., https://github.com/<User> ).
  2. Open repository
  3. Click tab Settings.
  4. Rename under Repository name (and press button Rename).

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.

  1. Verify that your local repo has everything committed and pushed (to remote origin).
  2. 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".)
  3. Locally remove your whole repo (e.g., rm -r project-original-name).
  4. 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.

Open git repository on browser, got to "Setttings", you can see rename button.

Input new "Repository Name" and click "Rename" button.

@Parison

Server Side: mv oldName.git newName.git
Client Side: ./.git/config change [remote "origin"] | url to newName.git
Related