Site icon David Yin's Blog

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 .

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.

Exit mobile version