gitrider

.gitignore won't work on front-end + back-end repo (keeps adding /.idea, /obj...)


Git keeps adding /.idea and /obj folder as changes, even though these directories are listed in .gitignore.

I have a repo with this folder structure:

repo/
├── .github/
│ └── workflows/
├── docker/
├── src/
│ ├── back-end/
│ └── front-end/
├── .gitignore

inside back-end there's a multi-project (DDD) ASP.NET Core app that i'm using Rider as IDE.

I already tried creating a .gitignore in ./src/back-end with "dotnet new gitignore" and it created the file in src/back-end/ correctly, but Git was still adding back-end/.idea and /obj to the changes.

I also tried using GitHub Desktop to create a .gitignore at the repo root with "/src/back-end/.idea" (right-click unwanted changes -> Ignore folder). It still didn't work. I committed the new .gitignore and pushed it, few seconds after "workspace.xml" from src/back-end/.idea was added as a change again. When doing "Ignore folder" again Github Desktop just adds the same line.

Edit: The "/obj" i mentioned are inside the projects in the back-end directory. Their changes are also being detected by git

src/
├── back-end/
│ ├── PlantCare.API/
│ │ └── obj/
│ ├── PlantCare.Application/
│ │ └── obj/
│ ├── PlantCare.Domain/
│ │ └── obj/
│ └── PlantCare.Infrastructure/
│ └── obj/


Solution

  • Once the files are in your repository, Git will track them. So delete those files (or move them out of the repo) make a commit and then they should not appear anymore.

    Example:

    rm -rf .idea
    git add .idea
    git commit -m "Delete .idea folder"