Loading...
Loading...
Compare original and translation side by side
git branch -d-Dgit branch -d/-Dgh pr merge --delete-branchgit worktree removegit branch -d-Dgit branch -d/-Dgh pr merge --delete-branchgit worktree removegit remote prune origin--prune[gone]-dgit remote prune origin--prune-d[gone]--all--dry-run--all--dry-runisolation: "worktree"git branch -dgh pr merge --delete-branchundefinedisolation: "worktree"git branch -dgh pr merge --delete-branchundefined
If worktree removal fails (e.g., uncommitted changes), report the issue to the user. Do not force-remove without confirmation.
**Gate**: No worktrees reference the target branch.
如果Worktree移除失败(例如存在未提交的更改),请向用户报告问题。未获得确认前请勿强制移除。
**检查点**:没有Worktree引用目标分支。BRANCH_TO_DELETE=$(git branch --show-current)MAIN_BRANCH=$(git symbolic-ref refs/remotes/origin/HEAD 2>/dev/null | sed 's@^refs/remotes/origin/@@' || echo "master")BRANCH_TO_DELETE=$(git branch --show-current)MAIN_BRANCH=$(git symbolic-ref refs/remotes/origin/HEAD 2>/dev/null | sed 's@^refs/remotes/origin/@@' || echo "master")git checkout "$MAIN_BRANCH" && git pull --prune origin "$MAIN_BRANCH"git checkout "$MAIN_BRANCH" && git pull --prune origin "$MAIN_BRANCH"git branch -d "$BRANCH_TO_DELETE"-dgit branch --format '%(refname:short) %(upstream:track)' | grep "$BRANCH_TO_DELETE"[gone]-D-Dgit remote prune origingit branch -d "$BRANCH_TO_DELETE"-dgit branch --format '%(refname:short) %(upstream:track)' | grep "$BRANCH_TO_DELETE"[gone]-D-Dgit remote prune originPR Cleanup Complete
- Switched to: [main branch name]
- Deleted local branch: [branch name]
- Pruned remote references
- Remaining local branches:
[list from git branch]git branchPR清理完成
- 已切换到:[主分支名称]
- 已删除本地分支:[分支名称]
- 已修剪远程引用
- 剩余本地分支:
[git branch命令的输出列表]git branch--allundefined--allundefined
Then delete all branches merged into main except protected branches:
```bash
git branch --merged "$MAIN_BRANCH" | grep -v -E '^\*|main|master|develop' | xargs -r git branch -dgit branch --format '%(refname:short) %(upstream:track)' | awk '$2 == "[gone]" { print $1 }'
然后删除所有已合并到主分支的分支(受保护分支除外):
```bash
git branch --merged "$MAIN_BRANCH" | grep -v -E '^\\*|main|master|develop' | xargs -r git branch -dgit branch --format '%(refname:short) %(upstream:track)' | awk '$2 == "[gone]" { print $1 }'/pr-cleanup-d/pr-cleanup-d/pr-cleanup feature/auth-flowfeature/auth-flowfeature/auth-flow/pr-cleanup feature/auth-flowfeature/auth-flowfeature/auth-flow/pr-cleanup-d[gone]-D/pr-cleanup-d[gone]-D[gone]git branch -D[gone][gone]git branch -D[gone]-Dgit checkoutgit checkoutrefs/remotes/origin/HEADgit remote set-head origin --automainmasterrefs/remotes/origin/HEADgit remote set-head origin --automainmastergit branch -D-d-d-Dgit branch -D-d-d-D--all--all