Best way to prevent large files from being tracked in Git? #194211
Answered
by
HariHara-sn
amirtha5225
asked this question in
Programming Help
-
🏷️ Discussion TypeQuestion BodyHello, I accidentally added some large log files and a heavy What is the correct way to remove these from the tracking history so my repo stays lightweight, and how do I prevent this from happening again? Thanks for the help! Guidelines
|
Beta Was this translation helpful? Give feedback.
Answered by
HariHara-sn
Apr 28, 2026
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi! This is a common issue. Here is how you can fix it:
Immediate Fix: Use the following command to remove the folder from the index without deleting it from your computer:
git rm -r --cached node_modulesgit rm --cached *.logPrevention: Create or update your
.gitignorefile at the root of your project and add these lines:History Cleanup: If the files are already in your remote history, you might need to use a tool like
git filter-repoorBFG Repo-Cleanerto completely scrub them from the past commits to shrink the repo size.After doing this, commit the changes and push. Your repo will be much cleaner!