Running git init creates a new Git repository in your project folder, but sometimes you run it in the wrong place or change your mind. This guide shows you exactly how to undo it—by deleting the hidden .git directory—so your folder goes back to being a normal, non-versioned directory. You only need a terminal and basic file navigation skills.
What You’ll Need
- A terminal or command prompt (Terminal on macOS/Linux, Command Prompt or PowerShell on Windows).
- Basic knowledge of
cd(change directory) andls(list files) commands. - If you have already committed files, make sure you have a backup (e.g., copy the folder or push to a remote) before deleting
.git, because this action removes all commit history and branches.
Step-by-Step
- Open your terminal and navigate to the project folder where you ran
git init. Usecd path/to/your/project. If you are already in the folder, you can skip this step. - Verify you are in the right directory by running
pwd(on macOS/Linux) orcd(on Windows) to print the current path. Double-check that this is indeed the folder you want to un-initialize. - Check that the folder is a Git repository by running
git status. If you see “fatal: not a git repository,” thengit initwas not run here, and you can stop. If you see a status message, you are in the right place. - List all files, including hidden ones, to confirm the
.gitdirectory exists. Runls -a(macOS/Linux) ordir /a(Windows). You should see a.gitentry. This is the folder that holds all Git data (commits, branches, config). - Delete the
.gitdirectory. This is the core step. Use the following command, but be absolutely sure you are in the correct folder first:- macOS/Linux:
rm -rf .git - Windows (Command Prompt):
rmdir /s /q .git - Windows (PowerShell):
Remove-Item -Recurse -Force .git
This permanently removes the repository metadata. Your project files (source code, documents, etc.) remain untouched.
- macOS/Linux:
- Verify the removal by running
ls -aagain. The.gitfolder should no longer appear. You can also rungit status—you should see “fatal: not a git repository,” which confirms the undo was successful. - Optional: Clean up other Git-related files that
git initmight have created. Usually,git initonly creates.git, but if you had a.gitignorefile, it is not created bygit init—it is created manually. So there is nothing else to delete. If you had a remote configured, it was stored inside.git, so it is gone too.
Common Mistakes
- Deleting the wrong folder. Running
rm -rf .gitfrom your home directory or another project will remove that project’s Git history. Always checkpwdandgit statusfirst. - Using the wrong command on Windows.
rm -rfis not recognized in Command Prompt. Usermdir /s /qor PowerShell’sRemove-Item. - Forgetting that
.gitis hidden. If you do not see it with a regularls, you might think it is not there. Always usels -aordir /a. - Thinking you can undo the undo. Once you delete
.git, the commit history is gone. There is no built-in Git command to recover it. Make sure you really want to remove the repository.
Tips
- Back up first. If you have commits you might need later, copy the entire project folder (including
.git) to a backup location before deleting. You can also push to a remote repository like GitHub or GitLab, then delete locally—you can clone it later if needed. - Use a GUI if you prefer. File explorers like Finder (macOS) or File Explorer (Windows) can show hidden files. On macOS, press
Cmd+Shift+.in Finder; on Windows, enable “Hidden items” in the View tab. Then you can right-click and delete the.gitfolder manually. - Consider re-initializing correctly. If you removed
.gitbecause you rangit initin the wrong place, you can simply rungit initagain in the correct directory. - Use
git initwith a branch name. For new projects, you can set the default branch name withgit init -b mainto avoid the old “master” default.
Troubleshooting
- “Permission denied” when deleting. On macOS/Linux, if you get a permission error, you might not own the folder or the
.gitfiles are protected. Trysudo rm -rf .git(use with caution) or check file permissions. On Windows, close any programs that might be using the folder (like an editor or terminal that has the directory open). - “The system cannot find the file specified.” This means the
.git folder does not exist. Maybe you are in the wrong directory or the repository was already removed. Runls -ato see what is there. - After deletion,
git statusstill shows something. If you are still in a subdirectory that was inside the old repository, you might be seeing the parent repository’s status. Move out of the folder and back in, or check if you accidentally deleted the wrong.git. - You deleted
.gitbut want the history back. If you have a remote, clone it again. If you have a backup, restore it. Otherwise, the history is gone—you cannot recover it without a backup.
Frequently Asked Questions
Does deleting .git delete my files?
No. The .git folder only contains version control metadata. Your working files (source code, documents, images) are separate and remain untouched.
Can I undo git init without deleting the whole folder?
No. The only way to undo git init is to remove the .git directory. There is no built-in “uninit” command.
Will my commits be lost?
Yes. All commit history, branches, and tags stored in .git will be permanently deleted. If you have pushed to a remote, you can clone it back, but any local-only commits will be gone.
What if I only want to remove the remote connection, not the whole repository?
If you want to keep the repository but remove the remote URL, use git remote remove origin (or whatever the remote name is). That does not delete .git or your history.
How do I check if a folder is a Git repository?
Run git status. If it shows “fatal: not a git repository,” then it is not. If it shows a status message, it is.
Can I re-initialize after deleting .git?
Yes. You can run git init again at any time to start fresh. This is useful if you want to restart version control from scratch.
Related
Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.
More cards in this drawer
- Jenkins vs GitHub Actions: Which CI/CD Fits Your Team?
- Turn Off Backup Encryption in iTunes?
- Campus Tech Innovation Hubs: What They Are
- Poco C51 Airtel Prepaid Locked Variant India?
- Shared VPS Hosting: Is It Better?
- Disk Defrag Pro: What It Does and Whether You Need It