“Are you sure you want to delete 5000+ files?”

Jason Kuffler
3 min readJul 29, 2022

--

Did I destroy my hard drive using git CLI?

If you hit a wall while learning to use git CLI and version control in general, you’ll want to read on.

I decided to share this info because I really didn’t feel like I could be a programmer without being able to quickly resolve this type of issue. I solved my issue eventually and today I helped out a student at codethedream.org with the same problem; albeit, on a different OS. I don’t want anyone to search down the wrong path as I did — so hopefully this helps someone!

Last year I set up a local repo to track my progress through The Advent of Code. Upon my first attempt at committing workable code, I saw something new. Something with a lot of RED text. . . similar to this example I found.

Desktop is an untracked folder? Cue the impending doom
Oh that don’t look good
seeing major directories on your drive being tracked is probably a no no — right?
I mean — why would I ever want to track my Desktop into a repository?!

Naturally one may decide: ok let’s search how to remove untracked files. Hey — perhaps that’s how you found this piece? You know you have solved a variety of problems by pouring over the pages of search results — so away I went through the decade-old stack overflow responses. Then I tried git docs. . . their docs were addressing other untracked-file related issues. I didn’t git it. At one point while following seemingly correct instructions — my PC alerted me to the fact I was attempting to delete over 5K different files. 🤦

I noticed the same process repeating in a fresh local repo. After a breather, I started tackling this untracked files issue again.

Eventually, I’m reading about the .git file that’s created each time we run git init ← it’s this command that creates the .git file that contains the boilerplate scripts that initialize our local repo. I confirmed this information on git docs and realized untracked files are only the symptom — not addressable directly lest one indeed wishes to potentially remove Desktop and other important directories.

I must’ve run git init on my root directory. I gotta git rid of .git

By this point, I had the fear that while cutting with a sharp knife on the CLI I risked erasing important parts of my drive — over 12 months of work would have to be backed up.

I did a bit of a foxhole prayer once I located the .git file on my c:// drive. This little folder was effectively making my entire PC's storage fair game in terms of git’s local repository operations.

The point is…You can delete the .git (if it’s not automatically hidden in your file explorer) at the root directory or whichever folder is causing git to track the unwanted directories || you can run the following on the CLI. Just make sure you’re running this at the root/parent directory that is bringing everything else along into the local repo!

rm -rf .git/

--

--

Jason Kuffler
Jason Kuffler

Written by Jason Kuffler

Creative. Researcher. Coder. Rad Dad. Sharing easy-to-follow progress covering my tech ed

No responses yet