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

Time:12-31

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

CodePudding user response:

Check the rules in the .gitignore file and try running the following commands. While your use uses the -r flag, in this case the -rf flag is used.

git rm -rf --cached .
git add .
git commit -m "gitignore is now working"
git push

The flags applied to the git rm command are described as follows:

  • -f Overrides the security check for making sure that the files in the HEAD correspond to the content of the staging index and working directory.
  • -r This is a shorthand for 'recursive'. The git rm removes a target directory and its whole content when working in recursive mode.

References

CodePudding user response:

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).

  • Related