How to force Git to “ignore” tracked files

git-icon

Well, well, well, you decided to start with the most incredible version control system: Git; you made your repository, start adding some commits, life was great! But suddenly, your realize there are some configuration files that started to be tracked by Git, because you forgot to add the famous .gitignore file.

Deleting those files is not an option because you need them, but those files are only interested/required for you, not for other team members. After researching a little bit, many people say there is no way to “ignore” files once they have been added to the repository; but don’t worry that is not totally true, there is a way to do that, let’s see it:

Remove the file from the index

git rm --cached PATH_TO_FILE

# Real example: I wanted to ignore the file ".settings"
git rm --cached wcm/libraries/WPS\ Design/.settings

Commit this “removed” operation

git commit -m "Remove .settings from the repository"

Add this file to the .gitignore and commit it

Edit the .gitignore file to include this new “ignored” file/folder:

# Add the new version of your .gitignore with the line to ignore the .settings file
git add .settings

# Commit
git commit  -m "Add .settings file to the .gitignore"

That’s it for today! Enjoy your day 🙂

One comment on “How to force Git to “ignore” tracked files”

Leave a Reply to My personal .gitignore file |

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