How to fully delete a local git repository created with git init

How to fully delete a local git repository created with git init

I know now you are stuck somewhere in your command line and Github repo. You probably want to remove the existing one and initialize a new one.

Okay, here is the solution.

Solution 1: Delete the .git directory

Git stores all files related to it in the .git directory.

The first solution is to remove the files.

This directory might not be showing up in your folders since it is mostly hidden.

For Windows users:

  1. Navigate to your project folder in File Manager.
  2. On the top click on the Views tab.
  3. On the right, you will see a checkbox Hidden Items. How to fully delete a local git repository created with git init.jpg
  4. Check the checkbox and a .git folder will be shown

For Mac-OS users:

There are two ways to view hidden files on Mac that is through Finder or through the Macs Terminal app.

View Hidden Files in Finder

  1. In Finder open your projects folder
  2. Press Command + Shift + .(a period) How to fully delete a local git repository created with git init.jpg
  3. The .git directory will appear
  4. Hit the same command to make the files invisible again

View Hidden Files in Macs Terminal App

  1. Open your Terminal under Launchpad > Other > Terminal. How to fully delete a local git repository created with git init1.jpg
  2. Run the command: defaults write com.apple.Finder AppleShowAllFiles true
  3. Press enter.
  4. Now run the command killall Finder
  5. Press enter and now you are able to see your hidden files.

Note: After you have removed the .git hidden folder run:

  1. Run the command: defaults write com.apple.Finder AppleShowAllFiles false
  2. Press enter
  3. Now run the command killall Finder
  4. Press enter, this will hide the hidden files again

For Ubuntu users:

  1. Just type Ctrl + H and all the hidden files will be shown

Solution 2: Delete all .git folders by running a command

To remove all of the repositories associated with git run the following command:

Make sure you are the in the right directory before running this command.

rm -rf .git

Or

rm -rf .git*

-rf(-r is for recursive and -f is to force the action)

To make sure the .git folder is removed run:

ls -lah

Solution 3: Delete all the .git folders using a different command

Run the following command to remove all .git related folders including .gitignore files and subfolders

find . -type f | grep -i "\.git" | xargs rm

Solution 4: Delete the entire project and restore it through backup

If the above solutions did not work for you might as well try to delete the project and then restore the backup.

  1. Delete all files except for .git
  2. On the command line run: git add . -A
  3. Next, run: git commit -m “deleting the entire project”
  4. Lastly: git push

Now you have to restore or create a backup of the project:

  1. Restore the backup or create a new project
  2. git add . -A
  3. git commit -m “recreating the project”
  4. Finally: git push

Solution 5: Killing the TortoiseGit

  1. Open TortoiseGit > Settings
  2. Navigate to the Icon Overlays option
  3. Now change the Status Cache from Default to None
  4. Now delete the directory
  5. Set back the Status Cache from None to Default
  6. It should now be working.

If any of the solutions did not work for you please comment below and let me know.