Safe Branch Squash previews and safely combines the local commits on a feature branch into one commit.
Current capabilities
The extension can:
- detect the Git repository for the active editor or workspace;
- let you choose a repository when a workspace contains several;
- suggest configured, remote-default, and common base branches;
- calculate the merge base with
HEAD; - display the commits that would be squashed;
- block protected branches, dirty worktrees, shallow clones, and active Git operations;
- create a verified Git bundle backup outside the visible branch graph;
- create one equivalent commit without changing the index or working tree;
- verify tree equality before and after atomically updating the branch;
- optionally update the upstream branch with an exact
force-with-lease.
It never pushes without an explicit Squash and Safe Push confirmation.
Usage
- Open a Git repository in VS Code.
- Run
Git: Preview Current Branch Squashfrom the Command Palette. - Select the branch your current feature branch started from.
- Review the ordered commit list.
To perform the local squash:
- Commit or stash all working tree changes.
- Hover the Source Control view title and click the
Combinebutton, or runGit: Squash Current Branch into One Commitfrom the Command Palette. - Select the base branch and review the commit list.
- Choose
Continue with Squash. - Enter the new commit message.
- Choose
Squash LocallyorSquash and Safe Pushin the final confirmation.
The success message includes the backup bundle path. The bundle preserves the original commits without adding another branch to the Git graph.
Settings
safeBranchSquash.baseRef: preferred base branch for the current workspace, such asorigin/main.safeBranchSquash.protectedBranches: branch names that cannot be rewritten. The defaults includemain,master,develop,stage, andstaging.
Development
Run npm run compile, press F5, and execute the commands in the Extension
Development Host window. Use a disposable repository when testing write flows.
Safety notes
The squash commit is created with git commit-tree, so normal pre-commit and
commit-msg hooks are not run. The current branch is updated with an expected old
HEAD value, preventing an unexpected concurrent branch change from being
overwritten. Safe push fetches the upstream first and uses its exact object ID as
the lease, so a concurrent remote update causes the push to fail.