gitignore does not ignore .idea directory

#idea folder
.idea/

This worked fine for me


Git never ignores changes to tracked files. As it appears as modified, the file is under version control (the idea/workspace.xml file usually should not be) and thus changes to it are tracked. Delete it from the index, leaving your local copy intact with git rm --cached .idea/workspace.xml and commit this change. From then on it will be ignored unless you force-add it back to the repository or change your gitignore settings.


Once you commit the file it will begin to be tracked.
In order to remove the file from this point you have to remove them from the repository.

What you need to do now is to delete the entire .idea folder, commit the deletion, add the idea extension to your .gitignore file.

Note

You can still ignore added files with the assume-unchanged flag

--[no-]assume-unchanged

When this flag is specified, the object names recorded for the paths are not updated.
Instead, this option sets/unsets the "assume unchanged" bit for the paths.

When the assume unchanged bit is on, the user promises not to change the file and allows Git to assume that the working tree file matches what is recorded in the index.

If you want to change the working tree file, you need to unset the bit to tell Git.

Git will fail (gracefully) in case it needs to modify this file in the index e.g. when merging in a commit; thus, in case the assumed-untracked file is changed upstream, you will need to handle the situation manually.


Explaining how to do from command line, can be done via IDEA as well.

# Remove the file from the repository
git rm --cached .idea/

# now update your gitignore file to ignore this folder
echo '.idea' >> .gitignore

# add the .gitignore file
git add .gitignore

git commit -m "Removed .idea files"
git push origin <branch>

Tags:

Git

Gitignore