Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Prakash4844/b8825d1eb764a1bb249d866bc6f7b1b8 to your computer and use it in GitHub Desktop.
Save Prakash4844/b8825d1eb764a1bb249d866bc6f7b1b8 to your computer and use it in GitHub Desktop.
This Gist Try to to fix a .gitignore that is not working.

How to fix a .gitignore that is not working

Sometimes, your .gitignore suddenly stops working as in even though you have added files and folder in it, they are not actually being ignored by git and is still getting tracked.

it might happen due to you have added the .gitignore after you added these files(That are not being ignored) to the repo.

it happens because, the files are already added to the repo before it could be ignored as .gitignore was created after the actual files in the repo.

Note that, The files/folder in your repository will not be deleted just because you added them to the .gitignore. They are already in the repository and you have to remove them manually.

You can just do that by following these steps:

  1. Open Terminal in the Repo directory.

  2. commit everything you've changed till now.

  3. To untrack a single file that has already been added/initialized to your repository, i.e., stop tracking the file but not delete it from your system, run this command in your terminal: git rm --cached filename

OR

  1. To untrack every file that is now in your .gitignore, run this command in your terminal: git rm -rf --cached . This removes any changed files from the index(staging area).

  2. Then run this command git add .

  3. Commit it by: git commit -m ".gitignore fixed, removed ignored files"

This is my first gist and it written just to check gist out

Reference: Git-Docs, Stackoverflow

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment