Working With Git. (Learn Your Mistakes before you make them)

Git is a powerful feature to help you keep version control of your files.

As a developer, just as with everything, you want to make sure you get adequate information regarding a command before using it.

So, my experience using git on VSCode brought about this writeup.

Inasmuch as I was able to rectify the issue, this is one mistake I don't want to make with a gigantic codebase containing thousands of files. It can cause nightmares to be honest.

So, I had been writing codes and pushing them to my repo on GitHub, then, I had the need to rename some of the files, this caused me to keep getting some errors on my git CLI each time I ran the command

git status

I felt the need to sync all changes with my origin(git Repo).

Roadblock 1: I was able to use git rm file1.js and this worked fine, but I had a file named try&catch.js which I couldn't remove because git treated the & in the name differently.

Roadblock 2: In the course of only trying to remove the file which I wanted to be deleted, I did git rm * and this removed all my files from my VSCode.

I was in shock as I didn't know what to do next.

The solution to Roadblock1: As you may have guessed that I changed the naming convention to something else, well that would have worked also, but I didn't do that.

What I did was implemented the escape syntax before the & sign in the name so My git code was git rm try\&catch.js and this worked awesomely!

The solution to Roadblock2: I used git reset and then git ls-files -d -z | xargs -0 git checkout -- and this restored back all my files for me.

I have never been more disturbed with the tremendous work and documentations I have been pushing all this while to my repo only to have it wiped out with a single mistake.

I hope you learn from my experience. I would share more of my coding journey and how I am able to master JavaScript by practicing, teaching, and most importantly pushing my codes and writeups to my GitHub using the GitHub commands.

These are the things you would be doing the most as a developer.

Like, share, Upvote, and give your honest feedback to help me create better content for you.

You can also support me as a developer so I can spend more quality time providing you with awesome content that would help you become a better developer.

You can now buy me a coffee:

No Comments Yet