How to Rename a Git Repository

John Wachira Feb 02, 2024
  1. Rename a Git Repository on GitHub
  2. Rename a Displayed Name in Git
  3. Rename a Repository Directory in Git
How to Rename a Git Repository

In this article, we will discuss renaming a Git repository. We can interpret this in different ways.

It can be renaming the displayed name, the repository on GitHub, or the repository’s folder. We will discuss these and go through the steps we need to follow.

Rename a Git Repository on GitHub

GitHub makes it easy for us to rename a repository. Follow these steps to rename your repo.

First, go to the Settings tab, and on the General Settings tab, you will find this.

rename a git repository

If we wanted to rename our DelftStack repo to another, we would enter the desired name and click Rename. It is as simple as that.

Of course, the repository’s URL will change, and we must set it in again in our local repo. We will copy the new URL, navigate our local repository’s folder and run the command below.

$ git remote set-url origin <new-URL>

After the change, Git will save the old repo and the associated URLs.

It will also redirect traffic to the new URL. Anyone using the old link will be redirected to the new one.

Rename a Displayed Name in Git

To change the displayed name, for example, by gitweb, follow these steps.

  • Open and edit the .git/description file to contain the desired name.
  • Save the file.

Rename a Repository Directory in Git

The local repository’s name is drawn from the repo’s directory if you are unaware. Hence to change the name, you will have to rename the directory.

You cannot rename the local repo without changing the directory’s name.

We use the git mv command to rename a directory. We run:

$ git mv <old-name> <new-name>

In a nutshell, GitHub allows us to change our repository’s name on the settings tab. You must set the new name on the command line using the git set remote - url command.

To rename a local repo, you will have to rename the directory containing the repo.

Author: John Wachira
John Wachira avatar John Wachira avatar

John is a Git and PowerShell geek. He uses his expertise in the version control system to help businesses manage their source code. According to him, Shell scripting is the number one choice for automating the management of systems.

LinkedIn

Related Article - Git Rename