Remove .idea or any files/dir from your git repo

We always try to do things faster and accidentally we add .idea directory and other unnecessary files.
I have faced this situation mostly for projects where there is no .gitignore generated automatically. Later on, when I try to check the repo from another machine or my team members see it then I feel like Oh! not again!

Here is the code to remove any files if you want to remove it from your git repository.

echo '.idea' >> .gitignore
git rm -r --cached .idea
git add .gitignore
git commit -m 'removed .idea'
git push

If you want to remove any other files or dir then follow the steps like above.

Example: Removing a file name .DS_Store in Mac:

echo '.DS_Store' >> .gitignore 
git rm -r --cached .DS_Store
git add .gitignore
git commit -m 'removed .DS_Store'
git push

Hope it helps you!

Written by

Tech Enthusiast

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store