Untrack files already added to git repository based on .gitignore

There is some files added to your git repository before you created .gitignore file. So they are already in the repos. Even you input the file name into .gitignore.  It is still there. Every time you change this file. It will be tere.

How to remove it?

Step 1: Commit all your changes.

It is the first step. Check your git status and commit all your changes. Including the .gitignore file.

Step 2: Remove everything from the repository

It is clean up. Enter following command:

git rm -r --cached .

  • rm is the remove command
  • -r  is an option to allow recursive removal
  • -cached will only remove files from the index. Your files will still be there, untouched.
  • The . indicates that all files will be untracked.

Step 3: Add everthing now

git add .

Step 4: Commit

git commit -m ".gitignore fix"

Step 5: Push

git push 

Then. Your repository is as clean as you expect.

Tags:, ,