Clean up old node_modules and Git branches on Windows

Every JavaScript project keeps its own node_modules folder, and build tools add caches beside it, such as .next or Rust's target folder. Across a dozen repos that adds up to gigabytes you never look at. Old Git branches take almost no disk space, but a long list of them makes it easy to switch to or delete the wrong one.

This post shows how RepoYard finds both and clears them without touching your code.

See where the space went

Open Machine, then Disk space. RepoYard checks every repo in your library and lists the folders it knows tools can recreate, with their sizes and a total at the top.

Two kinds of folder are listed. Build caches (.next, .nuxt, .svelte-kit, .turbo, .parcel-cache, .angular/cache, node_modules/.vite, node_modules/.cache, .dart_tool) come back on their own. Heavier folders (node_modules beside a package.json, and Rust's target beside a Cargo.toml) need an install or a full build to get back, so their label says so. Nothing else in a repo is ever deleted.

The Disk space tab shows 5.1 GB across 7 repos, with atlas-web at 796 MB and atlas-api at 2.8 GB marked Stop its dev server to clear these.
Each repo's caches and heavy folders, with their sizes.

Each repo's caches and heavy folders, with their sizes.

The Disk space tab shows 5.1 GB across 7 repos, with atlas-web at 796 MB and atlas-api at 2.8 GB marked Stop its dev server to clear these.

On a small screen, scroll across to read the full capture. Open original image

Clear build caches first

Select build caches ticks every build cache in repos with no dev server running. It leaves installed packages and build output unticked. Clearing a build cache also fixes most stale-build problems. The next start rebuilds it, so that start is slower.

Repos with a running dev server say "Stop its dev server to clear these" and can't be ticked, so you can't pull files from under a server that is using them.

Select build caches has ticked node_modules/.vite in design-system and .dart_tool in mobile-shell, and the button reads Clear 204 MB. The running atlas-web and atlas-api can't be ticked.
Select build caches skips installed packages and running repos.

Select build caches skips installed packages and running repos.

Select build caches has ticked node_modules/.vite in design-system and .dart_tool in mobile-shell, and the button reads Clear 204 MB. The running atlas-web and atlas-api can't be ticked.

On a small screen, scroll across to read the full capture. Open original image

Remove node_modules from projects you've finished with

For a project you haven't opened in months, its node_modules folder is usually the biggest item. Tick it and choose Clear. The confirmation reminds you to run install in that repo before you start it again.

RepoYard renames each folder before deleting it. If an editor or test watcher still has files open inside, the rename fails and the folder stays whole, with a message saying it is in use. A link or junction, which pnpm and monorepo tools create, is removed by itself: what it points to isn't touched.

The command line version, with PowerShell, is in Free up disk space from node_modules and build caches on Windows.

The confirmation Clear 529 MB? says the selected folders are deleted, code and settings are not touched, and to run install in those repos before starting them.
Heavy folders get a reminder to reinstall before the next start.

Heavy folders get a reminder to reinstall before the next start.

The confirmation Clear 529 MB? says the selected folders are deleted, code and settings are not touched, and to run install in those repos before starting them.

On a small screen, scroll across to read the full capture. Open original image

Delete merged branches, keep the risky ones

In a repo's Changes tab, open the branch menu and choose Clean up old branches. It lists local branches in three groups. Branches merged into main are ticked. Branches whose remote was deleted, and branches untouched for 90 days or more, are listed unticked, because they may hold commits found nowhere else.

A branch merged with squash or rebase on GitHub often lands in the second group: Git can't see its commits in main. Check it on GitHub before you tick it. RepoYard deletes a ticked merged branch only after Git confirms it is in main, and never deletes the current branch or main. Only local branches are deleted. Nothing on the remote changes.

For the Git commands and the squash-merge details, see Delete old Git branches safely on Windows.

The Clean up old branches dialog ticks fix/cart-rounding and chore/deps-september as merged, and leaves feat/apple-pay and experiment/edge-cache unticked with notes that they have commits only here.
Merged branches are ticked. Branches with commits only here are not.

Merged branches are ticked. Branches with commits only here are not.

The Clean up old branches dialog ticks fix/cart-rounding and chore/deps-september as merged, and leaves feat/apple-pay and experiment/edge-cache unticked with notes that they have commits only here.

On a small screen, scroll across to read the full capture. Open original image

What RepoYard does not do

  • It checks repos in your library only. Add older folders first with Add repos, then Scan a folder.
  • It doesn't say when you last worked on a project. You decide which ones are finished.
  • Cleared folders are deleted, not moved to the Recycle Bin.
  • It doesn't clear shared caches outside the repos, such as the npm cache or the pnpm store, or Python virtual environments.
  • Branch cleanup works one repo at a time.

Try it on your own repos.

Windows 10 and 11, x64. Every feature for 7 days, then US$39.99 once. No RepoYard account needed.

Get RepoYard from Microsoft