Keep your Git repo tidy and your team sane
Ever opened git branch
and seen a scroll of old, merged branches? Time to clean house.
🚀 Why You Should Clean Merged Branches
- Prevent clutter and confusion.
- Avoid accidentally working on stale branches.
- Improve project hygiene for the whole team.
🔥 One-Liner to Delete Merged Branches Locally
Here’s the safe and simple command to delete all locally merged branches except protected ones:
git branch --merged | egrep -v '^\*|main|master|release/staging' | xargs -n 1 git branch -d
🛡️ This skips the current branch (*
) and branches like main
, master
, and release/staging
.
☁️ Cleaning Up Remote Branches (Carefully)
To delete remote branches that are already merged:
git push origin --delete branch-name
💡 Pro tip: Use your Git hosting UI (GitHub, GitLab, Bitbucket) to confirm merge status before deletion.
🧠 Final Tip
Clean up regularly. Make it a habit at the end of each sprint or feature merge.
Comments
Post a Comment