Resync git repo with new gitignore file

After adding .gitignore file use following commands
[php]
git rm -r –cached .
git add .
git commit -m “.gitignore is now working”
[/php]

Make sure to commit first your changes you want to keep. The –cached option will keep your files untouched on your disk though.

Other more solution:
git rm --cached `git ls-files -i --exclude-standard`

Files with space in their paths

In case you get an error message like fatal: path spec ‘…’ did not match any files, there might be files with spaces in their path. You can remove all other files with option –ignore-unmatch:

git rm --cached --ignore-unmatch `git ls-files -i --exclude-standard`

But unmatched files will remain in your repository and will have to be removed explicitly by enclosing their path with double quotes:

git rm --cached ""

Nishant Vaity

Knowledgeable and skilled Technology Lead with an ability of software development and supervision. Possess a Bachelor of Science (BS) in Information Technology along with 11+ years of experience with hands-on coding and team management. By profession, I am a Software Engineer, Technology Mentor & Entrepreneur. Passionate about the technologies I use and always eager to share & learn more from that passion.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.