Git
Repository Management
Coding Solutions
Git Init
Deletion Guide

How can I fully delete a Git repository created with init?

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

Introduction

To fully delete a Git repository created with git init, remove the hidden .git directory at the root of your project. This directory contains the entire repository — all commits, branches, tags, configuration, and history. Once deleted, the folder becomes a plain directory with no version control. The working files remain untouched; only the Git metadata is removed.

Deleting the Repository

Linux / macOS

bash
cd /path/to/your/repo
rm -rf .git

rm -rf .git recursively removes the .git directory and all its contents. The -r flag handles directories, and -f prevents confirmation prompts for read-only files (Git marks some internal files as read-only).

Windows (Command Prompt)

cmd
cd C:\path\to\your\repo
rmdir /s /q .git

/s removes all directories and files in the specified directory, and /q runs in quiet mode without confirmation.

Windows (PowerShell)

powershell
cd C:\path\to\your\repo
Remove-Item -Recurse -Force .git

Windows (Git Bash)

bash
cd /c/path/to/your/repo
rm -rf .git

Git Bash on Windows uses Unix-style commands, so the same rm -rf .git command works.

What the .git Directory Contains

 
1.git/
2├── HEAD            # Points to current branch
3├── config          # Repository-specific configuration
4├── description     # Used by GitWeb (rarely relevant)
5├── hooks/          # Client-side hook scripts
6├── index           # Staging area (index file)
7├── info/           # Global exclude patterns
8├── objects/        # All commits, trees, blobs (your data)
9├── refs/           # Branch and tag pointers
10│   ├── heads/      # Local branches
11│   └── tags/       # Tags
12└── logs/           # Reflog history

When you delete .git, all of this is gone — every commit, every branch, every stash. The working tree files in your project folder are not inside .git, so they survive the deletion.

Verifying the Repository is Gone

bash
1# Before deletion
2git status
3# On branch main, nothing to commit...
4
5rm -rf .git
6
7# After deletion
8git status
9# fatal: not a git repository (or any of the parent directories): .git

The fatal error confirms Git no longer recognizes the directory as a repository.

Re-Initializing After Deletion

If you deleted the repository and want to start fresh with version control:

bash
1git init
2# Initialized empty Git repository in /path/to/your/repo/.git/
3
4git add .
5git commit -m "Initial commit"

This creates a brand-new repository with no history. All files in the directory start as untracked.

Deleting a Bare Repository

A bare repository (created with git init --bare) has no working tree — the Git data sits directly in the directory rather than inside a .git subdirectory:

bash
1# Bare repo structure
2my-repo.git/
3├── HEAD
4├── config
5├── objects/
6├── refs/
7└── ...
8
9# Delete the entire bare repo directory
10rm -rf my-repo.git

Bare repositories are typically used as remotes (servers). Deleting one removes the central copy that others may be pushing to.

Removing Git from a Subdirectory (Submodule)

If a subdirectory has its own .git (from a submodule or nested clone), delete that specific .git:

bash
1# Remove Git from a nested repo
2rm -rf path/to/submodule/.git
3
4# If it was registered as a submodule, also clean up:
5git submodule deinit path/to/submodule
6git rm path/to/submodule
7rm -rf .git/modules/path/to/submodule

Removing Remote Connection Only

If you want to keep the local repository but disconnect it from a remote (like GitHub), you do not need to delete .git — just remove the remote:

bash
1# List remotes
2git remote -v
3# origin  https://github.com/user/repo.git (fetch)
4# origin  https://github.com/user/repo.git (push)
5
6# Remove the remote
7git remote remove origin
8
9# Verify
10git remote -v
11# (empty)

This preserves all local history and branches while severing the connection to the remote server.

Common Pitfalls

  • Irreversible operation: There is no undo for rm -rf .git. All commit history, branches, stashes, and tags are permanently destroyed. If the repository was pushed to a remote, you can re-clone it, but any unpushed local work is gone.
  • Hidden directory on macOS/Linux: The .git directory is hidden (starts with .). Use ls -la to see it, not just ls. On Windows, enable "Show hidden files" in File Explorer or use dir /a in Command Prompt.
  • Permissions errors on Windows: Git marks some packfile objects as read-only. If rmdir /s /q .git fails, try closing any programs that might have files open (IDEs, terminal sessions), then retry. Git Bash's rm -rf handles this more reliably.
  • Accidentally deleting from the wrong directory: Always verify you are in the correct directory before running rm -rf .git. Running this in a parent directory could delete a different repository. Use pwd (Linux/macOS) or cd (Windows) to confirm your location.
  • Nested .git directories: If your project has submodules or was cloned inside another repo, there may be multiple .git entries. Deleting the top-level .git does not remove Git from subdirectories. Use find . -name .git -type d to locate all of them.

Summary

  • Delete a Git repository by removing the .git directory: rm -rf .git
  • The working tree files are not affected — only Git metadata is removed
  • The operation is irreversible — all history, branches, and stashes are destroyed
  • On Windows, use rmdir /s /q .git (CMD) or Remove-Item -Recurse -Force .git (PowerShell)
  • To keep history but disconnect from a remote, use git remote remove origin instead
  • For bare repositories, delete the entire directory (e.g., rm -rf my-repo.git)

Related reading
Free course
Beginner
7 lessons
2 hours
Tackling System Design Interview Problems

A short course that equips you with the skills to approach system design interviews methodically.

Start the free course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

All Rights Reserved.