···84848585Interactive rebasing is incredibly useful, as other options like `squash`, `break` or even `exec` are available. Just keep in mind that it makes more sense to do this on a branch where only you work to avoid team friction.
86868787+## Clean up local branches
8888+8989+When a PR is merged, the branch is usually deleted after it is safely merged into the default branch. But the branch still exists locally. If you want to delete all the local branches, which got deleted in your remote repository, you can run this command in most shells (use `wsl` on Windows):
9090+9191+```bash
9292+git fetch -p && git branch -vv | awk '/: gone] / {print $1}' | grep -v '^\*$' | xargs -I{} git branch -d "{}"
9393+```
9494+9595+:::caution
9696+This is a destructive action. Therefore I included a safeguard by using the lowercase `-d` parameter. If your branches are not cleanly merged, git will not delete them. If you are sure you want to delete all those branches no matter what, use `-D` instead.
9797+:::
9898+8799## Summary
8810089101**🛰️ Track Upstream Branch**
···95107> `git rebase -i HEAD~n`
96108>
97109> Use this to rewrite history. In the interactive editor, change `pick` to `reword` for any of the last `n` commits you want to modify.
110110+111111+**🧹 Prune Local Branches**
112112+> `git fetch -p && git branch -vv | awk '/: gone] / {print $1}' | grep -v '^\*$' | xargs -I{} git branch -d "{}"`
113113+>
114114+> A pipeline that identifies local branches whose remote counterparts have been deleted ("gone") and attempts to delete them safely.
9811599116## Resources
100117