DEV Community

sium_hossain
sium_hossain

Posted on

How can ignore a files that have already been committed to the repo?

If a file already committed and pushed into your github repo. And you forgot to add in .gitignore and make your push. Then you can ignore that file by ( make sure you add that file name in .gitignore ) -

Remove the files from the index (not the actual files in the working copy)

git rm -r --cached .
Enter fullscreen mode Exit fullscreen mode

Add these removals to the Staging Area

git add .
Enter fullscreen mode Exit fullscreen mode
git commit -m "your commit message"
Enter fullscreen mode Exit fullscreen mode

Voila 🐌

Top comments (2)

Collapse
 
webjose profile image
José Pablo Ramírez Vargas

This might actually be the first git CLI command I'll ever learn. This happens to me quite often, and I find myself doing the deletion, committing/ignoring/comitting path all over. Thanks!

Collapse
 
siumhossain profile image
sium_hossain

You are most welcome.
I'm glad you found this useful 😀
Please keep in touch for more 🤝