Search code examples
intellij-ideagitignore

Add file to ignored and remove it from the remote repository


I have a following case:

I made a .gitignore on gitignore.io. The .idea folder and project_name.iml were not in the ignore list and were pushed into the repo. I added them into the .gitignore, but they remain in the repo. If I make any changes to them, they appear in the list of changed files to commit. There is a way to get rid of them through the terminal

git rm -r --cached .idea/

But is it possible to start ignoring changes in those files and remove them from the repo by the IDE without using terminal?


Solution

    1. Remove the file/folder in Project tool window via the "del" key:
    2. Invoke "Undo" action to get them back. You will be asked if you want to add the files to git.
    3. Click "NO"
    4. Commit changes. The removed/re-added folder will be removed from git in the scope of this commit.

    Here is the short video demonstrating the process: enter image description here