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

  • Git and Mercurial - Compare and Contrast
  • git basic setup
  • Git: Pulling from Remote by Tag
  • What is “workspace polling” in the context of Jenkins?
  • Cannot use git from terminal
  • How can I edit my .git/config file?
  • git fetch: Cannot allocate memory
  • Creating patch of a git revision with Intellij
  • Finding the children of a git commit, not on the current branch, or any branch at all
  • How to upgrade the SVN version used by git-svn
  • programmatically delete .git .idx .pack files
  • Microservices: How to store source code of many microservices?
  • 3 Solutions collect form web for “Force git to update .gitignore”

    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.


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


    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.

    You will have to clear the cache first.

    • git rm -r --cached .
    • git add .
    • git commit -m "Suitable Message"

    Assuming here that your current working directory is empty.

    You can check what files git is currently tracking by using git ls-files. If you have a lot of files, you can use git ls-files | grep hello.txt to find if git is tracking that specific file.

    If it is tracking it, then use git rm hello.txt to untrack it (as Tim mentioned in his comment). Perhaps commit that untracked state first and then add it in to your .gitignore on your next commit. I have seen some funky behavior in the past when trying to ignore and remove in the same commit.

    Git Baby is a git and github fan, let's start git clone.