Branch Done
After opening a PR, delete the current feature branch and switch back to the base branch.
When to apply
Cleaning up the main checkout after opening a PR. Do not apply inside a worktree — that is worktree-done.
Steps
- Record the current branch name:
git rev-parse --abbrev-ref HEAD. - Determine the base branch:
- Try
git symbolic-ref refs/remotes/origin/HEADand strip therefs/remotes/origin/prefix. - If that fails, use the first of
dev,main,masterthat exists locally (git show-ref --verify --quiet refs/heads/<name>). - If none exist, stop and ask the user which branch is the base.
- Try
- If the current branch is the base branch (or is itself
dev,main, ormaster), stop and notify the user — nothing to clean up. - Checkout the base branch and pull latest:
git checkout <base branch> && git pull - Delete the previous feature branch locally:
git branch -D <recorded branch> - Confirm in one line:
Cleaned up → back on <base branch>, deleted <branch>