Search code examples
gitgitignore

Git keeps adding files in .gitignore on first commit and push to remote


I am trying to do my first commit and push to github. Originally my angular/cache was not in the gitignore file. Now I have added it and tried to commit and push but it keeps including the angular/cache dir ie it keeps trying to add previously tracked stuff I think.

Things I have tried:

git rm -r --cached . && git add . && git commit -am "Remove ignored files"
git push -u origin master

I have also tried git update-index --assume-unchanged .angular/cache

Everytime I the filed keep adding


Solution

  • A .gitignore file only prevents untracked files from being added to the index [1], so that if you run git add the files listed there will not be added. It does not remove already added files from the index ! Why removing the files from the index does not help I have no idea, but it should work if you rm -rf the .git folder and re-init a new repository (i.e. start your git repository from scratch).