Search code examples
gitgitignore

Force git to update .gitignore


I have a .gitignore file, and it's ignoring some files. I have updated the .gitignore file (removed some filenames and added some filenames). This is not reflected in git status. How can I force git to update these changes, so that track files which are not tracked before and vice versa.

I have tried this question, still all of my files are not tracked (according to my updated .gitignore). (In simple, how can I force git to retract files once .gitignore is updated or deleted).


Solution

  • If you want to add all files, delete all filenames from .gitignore file, not the .gitignore file and commit it, then try

    git config --global core.excludesfile ~/.gitignore_global

    Some files are ignored by the git depending on the OS (like .dll in windows). For more information.

    Now

    git add .
    
    git status
    
    git commit -m "your message"
    

    Or

    You can try a simple hack, it may or may not work. Delete all filenames from .gitignore file and add this line !*.*, then add and commit.

    UPDATE

    Simple, I'll explain with an example. Say you have a build folder which is already added and tracked by git. Now you decide not to track this folder.

    1. Add this folder (build) to .gitignore
    2. Delete build folder
    3. Commit your changes

    From now on git will not track build folder.