How to rename a git repository?

牧云@^-^@ 提交于 2019-11-29 18:31:47
Alex Brown

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 (e.g., 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 (e.g., 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 (e.g., 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 (e.g., 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 repo doesn't have a name. You can just rename the directory containing your worktree if you want.

Alex

Rename PRJ0.git to PROJ1.git, then edit the URL variable located in the .git/config file of your project.

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 repo will not change it on the remote.

Droogans

If you meant renaming your repository, go to your repo and click "admin", then rename.

Once you see the red box warning you about some sky-fallingness and other things, go read this question.

Neha Kumari

To rename any repository of your git-hub:

  1. Go to that particular repository which you want to rename
  2. Navigate to the settings tab
  3. There, in the repository name section, type the new name you want to put and click rename
Parison
  • On the server side, just rename the repository with 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
    

Worked for me.

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

git itself has no provision to specify the repository name. The root directory's name is the single source of truth pertaining to repository name.
The .git/description though is used only by some applications like Gitweb

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.

for aws codecommit users,

aws codecommit update-repository-name --old-name MyDemoRepo --new-name MyRenamedDemoRepo

reference: here

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

  1. Go to the remote host (e.g., https://github.com/User/project).
  2. Click tab Settings.
  3. Rename Repository name.
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!