I have Initialized a git repository and have made some commit in that now for some reason I do not want to track any files in it and want to remove git from my local repo. Is there some way I can Uninitialize it?
6 Answers
git stores all the repository related data in a folder named ".git" inside your repository folder. So you just want to keep your files but change it into a "not-git-repository". Warning: this is irreversible!
cd path/to/repo
rm -rf .git
The only files that might remain are hidden ".gitignore" files (but only if you added them yourself or using some tool like eclipse). To remove them:
find . -name ".gitignore" | xargs rm
-
-
-
Please also tell me if that remove will be permanent or still I can undo it?– NaseerMar 20, 2014 at 17:28
-
2Warning: Before running
rm -rf .git
, make sure that this is really the repo you want to "uninitialize". That command will irreversibly (well, almost irreversibly) destroy all of your repo's history, leaving only the files currently in the wroking directory.– Ajedi32Mar 20, 2014 at 18:05 -
@khan
-r
means 'recursive'. It's required for deleting folders.-f
means "force". It's required for deleting protected files.– Ajedi32Mar 20, 2014 at 18:07
Just deleting the .git
directory stored in the repository will pretty much do it.
-
>pretty much is relevant here. I'm working on a unique case, but rm -rf *, .git, everything. a wipe of the directory to ls -a producing "." and ".." only, followed by "git log" yields previous commits May 6, 2022 at 1:24
Go to "File Explorer Options" in the control panel, there go to "View" and check the option that allows you to see the hidden folders.
Then go to the folder where you want to un-initialize the git repository and you will find a folder called ".git" (it will be slightly faded since it's a hidden folder).
Deleting this folder will do the trick.
go to the folder where you initialized git ,check on the hidden files we can see .git file deleting that file solves our problem
-
2Its a folder, not a file. Also, the same answer was provided by another user.– MansoorOct 31, 2020 at 16:40
Sometimes this may be a folder permission issue so the comments above definitely will help.
If you are using a linux distro try this command
chown -R <current_user> <repo_folder>
For example in my devcontainers I used with VSCode i had this issue and running
chown -R node .
solve this issue.
If the . and .. owners of the folder when you run ls -la
are different from files in the folder, git evaluates this and needs specific override to initialise it so if that may be correct then you will need to use this command below to add an exception to git
git config --add safe.directory 'project_path' --global
Hope that help :)
I put rm -rf .git
in the terminal then
I removed .gitignore
from one of my project's folders and added it to the root but it didn't work.
ctrl + shift + p
> reload window
didn't ignore the +3K
changes in my source control tree either.
Surprisingly, when I closed vscode and re-open it again it successfully responded to the changes.