Almost deleted the entire contents of my computer, how to prevent this in the future?

I guess I’m glad I did this while learning, rather than on the job…

I was trying to set up VS Code for the “Portfolio Project: Personal Portfolio Website” project, when I noticed that the git hub integration within VS Code had tracked more than 10,000 changes, and because of that had stopped updating. I looked and realized that it had been tracking every change made on my computer for the past couple weeks.

I thought I fixed it by initializing a different Github project. Clearly this was not the case, because when I went to clear out what I thought was just logs of all the changes in VS Code (and not the files themselves), it started deleting every file on my computer, lmfao.

Luckily I realized what was happening almost immediately, and I also have a backup of my hard drive from a few days ago that I’m going to restore from. My question is, what are some likely scenarios that would have caused this, and how can I prevent it in the future?

I’d try to provide more info, but I’m afraid that if I open VS Code again it’ll delete my computer, and I’m so caffeinated right now I’d probably have a heart attack lmfao