W3docs

How to Delete Git Repository Created with Init

In this tutorial, you will find out two methods of deleting the git repository created with the git init command for Linux and Windows operating systems.

Warning: Deleting the .git directory permanently removes all version history and cannot be undone.

Solution for Linux

To undo the changes made by git init, you should delete the git repository. Follow the steps below to complete this.

  1. Open the Terminal by typing the <kbd class="highlighted">Ctrl</kbd> + <kbd class="highlighted">Alt</kbd> + <kbd class="highlighted">T</kbd>
  2. Next, type the following command to delete the <kbd class="highlighted">git repository</kbd> and undo the changes made by <kbd class="highlighted">git init</kbd>:

Delete the Git Repository

rm -rf .git

Solution for Windows

The method to undo the changes for Windows differs from other operating systems. Here are the steps to follow.

  1. Open the Run prompt by pressing <kbd class="highlighted">Windows</kbd> + <kbd class="highlighted">R</kbd>.
  2. Then, type <kbd class="highlighted">cmd</kbd> and press <kbd class="highlighted">Shift</kbd>+<kbd class="highlighted">Ctrl</kbd>+<kbd class="highlighted">Enter</kbd> to provide administrative privileges.
  3. Run the following to delete the repository and press <kbd class="highlighted">Enter</kbd>:

Delete a repository and undo changes for Windows

rmdir .git

If the repository has subfolders, then execute:

Delete a repository with subfolders

rmdir /s .git

Solution for Mac OS

In this section, we will demonstrate two ways to show hidden files and delete them on Mac OS.

  1. For the first method, open the Terminal and run the following command:

Show hidden files for Mac OS

defaults write com.apple.finder AppleShowAllFiles 1 && killall Finder
  1. Press <kbd class="highlighted">Cmd</kbd> + <kbd class="highlighted">Shift</kbd> + <kbd class="highlighted">.</kbd> in Finder to display hidden files.
  2. Type <kbd class="highlighted">cd</kbd>, drag your repository folder from Finder into the Terminal window, and press <kbd class="highlighted">Return</kbd>.
  3. Finally, move the .git folder to the Trash.
  4. For the second method, navigate to the repository's root folder in the Terminal and run:

Delete a repository for Mac OS

rm -rf .git

The git init Command

The <kbd class="highlighted">git init</kbd> command generates a new, empty <kbd class="highlighted">git repository</kbd> or reinitializes an existing one. A repository stores project files, which allows you to track code versions and access them. This command creates a .git subdirectory that contains metadata, such as object directories and template files for generating a new repository.