Skip to content
| Marketplace
Sign in
Visual Studio Code>Other>Git Branch CleanNew to Visual Studio Code? Get it now.
Git Branch Clean

Git Branch Clean

FENG QIN

|
2 installs
| (1) | Free
检查并清理长期未处理的本地 Git 分支。
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
Copied to clipboard
More Info

Git Branch Clean

English | 简体中文

Git Branch Clean is a VS Code extension for finding and safely cleaning up stale local Git branches in the current workspace.

Install from Visual Studio Marketplace:

Open Git Branch Clean in Marketplace

Open the link, click Install, and start using the command in VS Code.

It checks local branches that have already been merged into your configured main branches, plus unmerged branches whose latest commit age reaches the configured threshold, and lets you safely delete selected branches with git branch -d.

See CHANGELOG.md for release notes.

Features

  • Run from the Command Palette: Git Branch Clean: 检查过期分支
  • Default keybinding:
    • macOS: Cmd+Alt+B
    • Windows/Linux: Ctrl+Alt+B
  • Checks local branches only. Remote branches are not scanned or deleted.
  • Supports multiple main branch names, separated by commas. Default: main,master
  • Merged branches are not limited by the stale threshold and are preselected in Quick Pick, so pressing Enter safely deletes them.
  • Unmerged branches are shown only after they reach the stale threshold. Default: 720 hours, equal to 30 days.
  • Optionally fetches remote refs before scanning and uses remote main branches, such as origin/main, for merge detection.
  • Unmerged stale branches require a second Quick Pick confirmation, without selecting the same branches again.
  • Supports include and exclude branch patterns with * wildcards.
  • Uses safe deletion first: git branch -d -- <branch>.
  • If safe deletion fails, it asks before force deleting failed branches with git branch -D -- <branch>.

Settings

{
  "gitBranchCleanup.mainBranch": "main,master",
  "gitBranchCleanup.staleHours": 720,
  "gitBranchCleanup.includeBranchPatterns": "chore/*,feature/*",
  "gitBranchCleanup.excludeBranchPatterns": "chore/keep-*",
  "gitBranchCleanup.fetchRemoteBeforeScan": false
}

gitBranchCleanup.mainBranch

Comma-separated main branch names used to determine whether a local branch has been merged.

Default:

"main,master"

gitBranchCleanup.staleHours

How many hours since the latest commit before a local branch is considered stale.

Default:

720

gitBranchCleanup.includeBranchPatterns

Comma-separated branch patterns to include in the scan. Supports *.

Default:

"*"

gitBranchCleanup.excludeBranchPatterns

Comma-separated branch patterns to exclude from the scan. Supports *.

Default:

""

gitBranchCleanup.fetchRemoteBeforeScan

Whether to run git fetch --all --prune before scanning and include remote main branch refs in merge detection.

Default:

false

Cleanup Behavior

The extension always tries Git's safe delete command first:

git branch -d -- <branch>

If Git refuses to delete a branch, usually because it is not considered fully merged, the extension shows the failure and asks whether to force delete only those failed branches:

git branch -D -- <branch>

Force delete only runs after explicit confirmation.

Development

pnpm install
pnpm run compile
pnpm test
pnpm run package:vsix

Press F5 in VS Code to start an Extension Development Host for manual testing.

Release

GitHub Releases are published by .github/workflows/release.yml.

  1. Update package.json version and CHANGELOG.md.
  2. Commit the release changes.
  3. Create and push a matching tag:
git tag v0.1.5
git push origin v0.1.5

The workflow verifies that the tag matches the package version, runs tests, packages the extension, and uploads the generated VSIX to the GitHub Release.

  • Contact us
  • Jobs
  • Privacy
  • Manage cookies
  • Terms of use
  • Trademarks
© 2026 Microsoft