How to Delete Git Repository Created with Init

  1. Solution for Linux
  2. Solution for Windows
  3. Solution for Mac OS
  4. The git init Command

Solution for Linux

To undo the changes made by git init you should delete the git repository. Follow the steps below to make the job done.

  1. Open the Terminal by typing the Ctrl + Alt + T
  2. Next type the following command line which will delete the git repository and undo the changes made by git init:
rm -rf .git

Solution for Windows

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

  1. Open the Run prompt by pressing Windows + R.
  2. Then, type cmd and press Shift+Ctrl+Enter to provide administrative privileges.
  3. Run the following to delete the repository and press Enter:
rmdir .git

If the repository has subfolders, then execute:

rmdir /s .git

Solution for Mac OS

In this section, we will demonstrate to you two ways of detecting the hidden files and deleting them in Mac OS.

  1. In the framework of the first method, first, you should open the terminal and run the code below:
    defaults write AppleShowAllFiles 1 && killall Finder

    Then, you should type cmd + SHIFT +. to display hidden files in Finder.

    Then, you should also type cd, drop your git repository folder from Finder to the Terminal window, and press return.

    And, finally, you can delete them by just moving them to trash.

  2. In the framework of the second method, first, you should navigate to the root folder of the repository and run the command below:
    rm -rf .git

The git init Command

The git init command generates a new, empty git repository or reinitializes an existing one. A repository is a storage of the project files, which makes it possible to save code versions and have access to them. This command creates a .git subdirectory which includes the metadata, like subdirectories for objects and template files to generate a new repository.

Do you find this helpful?

Related articles