Git

How Do I Delete a Local Repository in Git?

When developers work on team projects, they need to create local repositories and perform multiple operations on them, which are required for project development. After completing their operations, they want to remove or delete the corresponding local repository. To do so, utilize the “$ rm -fr <repo-name>” command in the Git bash terminal.

This guide provides the process of deleting a local repository in Git.

How Do I Delete a Local Repository in Git?

To remove the Git local repository, first, we will navigate to the Git root directory and create a local repository. Then, list the content of the root directory. Lastly, run the “$ rm -fr <repo-name>” command to delete the Git local repository.

Now, implement the above-discussed instructions for better understanding!

Step 1: Navigate to Git Root Directory

First, move to the Git root directory using the following command:

$ cd "C:\Users\nazma\Git"

Step 2: Create Git Local Repository

Now, execute the “mkdir” command to create a new Git local repository:

$ mkdir Demo18

Step 3: List Root Directory Content

Next, view the list of Git root directory content to ensure if the new repository is created using the following command:

$ ls

As you can see that, a new repository named “Demo18” is created successfully:

Step 4: Delete Local Repository

Execute the “rm” command with the “-fr” option and specify the name of the local repository you want to delete:

$ rm -fr Demo18

Step 5: Verify Deleted Repository

Lastly, view the list of Git root directory to ensure the deleted Git local repository:

$ ls

According to the below output, the deleted “Demo 18” local repository does not exist in the root directory:

That’s it! We have offered the easiest way to remove a local repository in Git.

Conclusion

To delete the Git local repository, first, navigate to the Git root directory and create a local repository. Then, list the content of the root directory. Now, execute the “$ rm -fr <repo-name>” command to delete the Git local repository. Lastly, run the “$ ls” command to ensure the deleted local repository. This guide demonstrated the easiest method to delete a local repository in Git.

About the author

Maria Naz

I hold a master's degree in computer science. I am passionate about my work, exploring new technologies, learning programming languages, and I love to share my knowledge with the world.