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.
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
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)
/s removes all directories and files in the specified directory, and /q runs in quiet mode without confirmation.
Windows (PowerShell)
Windows (Git Bash)
Git Bash on Windows uses Unix-style commands, so the same rm -rf .git command works.
What the .git Directory Contains
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
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:
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:
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:
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:
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
.gitdirectory is hidden (starts with.). Usels -lato see it, not justls. On Windows, enable "Show hidden files" in File Explorer or usedir /ain Command Prompt. - Permissions errors on Windows: Git marks some packfile objects as read-only. If
rmdir /s /q .gitfails, try closing any programs that might have files open (IDEs, terminal sessions), then retry. Git Bash'srm -rfhandles 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. Usepwd(Linux/macOS) orcd(Windows) to confirm your location. - Nested .git directories: If your project has submodules or was cloned inside another repo, there may be multiple
.gitentries. Deleting the top-level.gitdoes not remove Git from subdirectories. Usefind . -name .git -type dto locate all of them.
Summary
- Delete a Git repository by removing the
.gitdirectory: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) orRemove-Item -Recurse -Force .git(PowerShell) - To keep history but disconnect from a remote, use
git remote remove origininstead - For bare repositories, delete the entire directory (e.g.,
rm -rf my-repo.git)
Related reading
- How can I fully delete a Git repository created with init?
- How can I generate a Git patch for a specific commit?
- How can I get a list of Git branches, ordered by most recent commit?
- How can I get my C code to automatically print out its Git version hash?
- How can I get the assembly file version
- How can I get the diff between all the commits that occurred between two dates with Git?
- How can I get the latest tag name in current branch in Git?
- How can I Git ignore subfolders / subdirectories?
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseTrack 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.