Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I rename a Git repository?

Tags:

git

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

like image 518
Yantao Xie Avatar asked Jan 11 '10 13:01

Yantao Xie


2 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, [email protected]:User/project-new.git)
  5. Set the new URL using Git:

    git remote set-url origin [email protected]:User/project-new.git 
like image 101
Alex Brown Avatar answered Sep 27 '22 19:09

Alex Brown


A Git repository doesn't have a name. You can just rename the directory containing your worktree if you want.

like image 38
Tobu Avatar answered Sep 27 '22 19:09

Tobu