Home Projects Portfolio Dashboard Export PDF Log in

Cleaning Up Your Repository: Managing Node.js Dependencies

The Problem

When working on the el-lector-voraz project, we noticed that our repository size was growing unexpectedly. We identified that the node_modules directory had been accidentally committed to the source control. Including dependencies in the repository bloats the git history, slows down cloning processes, and leads to cross-platform compatibility issues.

The Approach

To clean up the repository and ensure a healthy development environment, we focused on proper dependency management practices.

Removing Bloat

The primary task involved removing the local dependency folder from tracking while ensuring that future installations remain managed via the standard package manager workflow.

# Remove the directory from the index, but keep it on disk
git rm -r --cached node_modules

# Commit the deletion
git commit -m "Remove node_modules from repository"

Preventing Future Pollution

To prevent this from recurring, we updated the .gitignore file. This ensures that the environment-specific dependency folder is never tracked, forcing every developer to install dependencies fresh based on the package.json lock file.

# .gitignore
node_modules/
*.log
.env

Best Practices for Dependencies

  • Never Commit node_modules: This directory contains machine-specific binaries and large amounts of small files that clog git.
  • Use .gitignore: Always explicitly define build outputs and dependency folders as ignored.
  • Lock Files: Always commit package-lock.json or yarn.lock to ensure consistent dependency versions across different machines.

Key Insight

Your repository should only track source code and configuration. By automating dependency installation via CI/CD or developer setup scripts, you keep your repository lightweight and your builds reproducible. If you see large file changes in your git history, check your ignore files first.


Generated with Gitvlg.com

Cleaning Up Your Repository: Managing Node.js Dependencies
Daniela Homobono

Daniela Homobono

Author

Share: