Skip to content
Discussion options

You must be logged in to vote

git rm -r --cached node_modules
git rm --cached .env
echo "node_modules/" >> .gitignore
echo ".env" >> .gitignore
git add .gitignore
git commit -m "chore: stop tracking node_modules and .env"
git push

--cached removes the files from Git only, not from your disk. .gitignore only affects untracked files, which is why you must untrack them first.

Important: If .env held real secrets (API keys, DB passwords), they’re still in the old commit history. Rotate those secrets immediately, then optionally purge history with git filter-repo or BFG Repo-Cleaner. Commit a .env.example with dummy values so others know which variables are needed.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by Nova-Developer18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Repositories The core of version-controlled code storage Question Ask and answer questions about GitHub features and usage source:ui Discussions created via Community GitHub templates
2 participants