A Cleanup Script Deleted the develop Branch — Git Delete Branch

A nightly cleanup script deleted the develop branch because it didn't exclude protected branches, and CI failed with 'branch not found.' This is deleting branches safely: local vs remote deletion, -d vs -D, recovering a deleted branch via reflog, and protecting the branches you can't afford to lose. ⏳ Timestamps: 0:00 - Cold open: git fetch showed - [deleted] (none) - origin/develop 0:10 - Intro 0:16 - What Is Git Branch Deletion? 0:34 - Safe Delete: git branch -d 0:59 - Force Delete: git branch -D 1:24 - Inspect Before Force-Delete 1:50 - Delete Remote Branch 2:18 - Prune Local Tracking Refs 2:40 - Full Cleanup Workflow 3:02 - Bulk Delete with Exclusions 3:24 - Recover Deleted Branch via Reflog 3:52 - git fetch showed - [deleted] (none) - origin/develop 4:17 - The Fix 4:37 - ⚠ Gotcha: Running bulk delete without excluding protected branches 4:51 - ⚠ Gotcha: Deleting remote branch but not pruning locally 5:03 - ⚠ Gotcha: Using -D when -d fails without investigating 5:17 - Recover Deleted Remote Branch via GitHub API 5:36 - Git Version Compatibility for --delete 6:12 - Debugging Guide 6:30 - Interview Questions 6:56 - FAQ 7:21 - Key Takeaways 7:38 - Next up 7:54 - Wrap-up 👉 Full article + code: https://thecodeforge.io/devops/git-de... ⏭ Next up: Git Squash Commits: Combine Multiple Commits into One #git #devops #versioncontrol