When renaming a Git repository, it can be divided into two main parts: renaming locally and renaming remotely (e.g., on GitHub, GitLab, etc.).
Renaming the Local Repository
-
Change the Local Folder Name
This is the most straightforward step; directly rename the folder containing your Git repository in the file system. For example, if your repository is namedold-repoand you want to rename it tonew-repo, you can modify it directly in your file browser or use the command line:bashmv old-repo new-repo -
Update Git Configuration
Typically, renaming the local folder name does not require modifying Git configuration, as Git focuses on the internal.gitfolder and its contents. You only need to update references if scripts or configurations explicitly reference the old path.
Renaming the Remote Repository
Renaming a remote repository is slightly more complex and depends on the service used (e.g., GitHub, GitLab). For example, with GitHub, follow these steps:
-
Log in to GitHub
Open GitHub in your browser and log in to your account. -
Navigate to Repository Settings
Enter the repository you want to rename and click the "Settings" tab on the repository page. -
Modify Repository Name
On the settings page, locate the "Repository name" field, enter the new name, and save the changes. -
Update the Remote URL of the Local Repository
After renaming the remote repository, update the local repository's remote URL to ensure future push and pull operations target the new address. Use this command:bashgit remote set-url origin new_repository_urlYou can find the new repository URL under the "Code" tab of the GitHub repository.
Example
Suppose you have a GitHub repository named old-repo that you want to rename to new-repo. Follow the steps above, and remember to update the remote URL in your local Git configuration.
By following these steps, you can effectively manage and update your Git repository name, ensuring your project management and version control system remain organized and tidy.