Vannkorn

Full Stack Web Developer

Close

Git: ignore files that are already tracked

This happened to me recently when I dived into the Next JS project with WordPress as a headless CMS.

Ads: Register now via this link to receive $300 credit from Vultr

As a developer, forgetting to ignore files before the commit is one of the common mistakes. This happens when we’re diving into new projects with different technologies we’re not quite experienced with.

This happened to me recently when I dived into the Next JS project with WordPress as a headless CMS. At that time, putting which files under revision is blank to me. I repeatedly forgot to add files to my .gitignore list as some files were only created after the build.

If you ever commit the same mistake to me, follow the same steps below:

git rm --cached <Filesyou have previously mistakenly added to git>

If it’s a folder use -r

git rm -r --cached <Filesyou have previously mistakenly added to git>

By doing this, the file/folder you have mistakenly tacked before will be deleted from the repository, and you may now add it to your .gitiignore list.

Leave a Reply

Your email address will not be published. Required fields are marked *