Skip to content

Instantly share code, notes, and snippets.

@suhailroushan13
Last active January 30, 2026 09:58
Show Gist options
  • Select an option

  • Save suhailroushan13/abf807069afe923c9483cb0f9ee82db3 to your computer and use it in GitHub Desktop.

Select an option

Save suhailroushan13/abf807069afe923c9483cb0f9ee82db3 to your computer and use it in GitHub Desktop.
Git node_modules
Scenario What To Do
You ran git add . and node_modules got staged git reset node_modules/
• Add node_modules/ to .gitignore
git add .gitignore
git commit -m "Fix: removed node_modules"
git push origin main/master
You ran git commit and node_modules got committed git rm -r --cached node_modules
• Add node_modules/ to .gitignore
git commit -m "Remove node_modules"
git push origin main/master
You ran git push and node_modules is on GitHub git rm -r --cached node_modules
• Add node_modules/ to .gitignore
git commit -m "Remove node_modules"
git push origin main --force
Scenario What To Do
1. Undo last commit (but keep changes) git reset --soft HEAD~1
2. Undo last commit (delete the changes) git reset --hard HEAD~1
3. Unstage a file accidentally added git reset fileName
4. Remove a file/folder from commit before push git rm --cached fileOrFolder
git commit -m "Remove file"
5. Remove file/folder from Git after pushing git rm --cached fileOrFolder
git commit -m "Remove file"
git push
6. Remove file/folder from entire Git history git filter-repo or BFG tool (advanced)
7. Delete wrong commit from GitHub git reset --hard HEAD~1
git push --force
8. Restore a deleted file from history git checkout HEAD~1 fileName
9. Revert a specific commit without touching others git revert <commit-hash>
10. Delete node_modules after push git rm -r --cached node_modules
.gitignore
git commit
git push --force
11. Delete large files that increased repo size Use git filter-repo to remove them everywhere
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment