PHPackages                             jeffersongoncalves/git-worktree-cli - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [CLI &amp; Console](/categories/cli)
4. /
5. jeffersongoncalves/git-worktree-cli

ActiveProject[CLI &amp; Console](/categories/cli)

jeffersongoncalves/git-worktree-cli
===================================

CLI tool to audit git worktrees and check whether their branches have been merged into the main branch.

1.0.1(1mo ago)23MITPHPPHP ^8.2CI passing

Since Apr 16Pushed 1mo agoCompare

[ Source](https://github.com/jeffersongoncalves/git-worktree-cli)[ Packagist](https://packagist.org/packages/jeffersongoncalves/git-worktree-cli)[ Docs](https://github.com/jeffersongoncalves/git-worktree-cli)[ GitHub Sponsors](https://github.com/jeffersongoncalves)[ RSS](/packages/jeffersongoncalves-git-worktree-cli/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (7)Dependencies (5)Versions (8)Used By (0)

[![Git Worktree CLI](https://raw.githubusercontent.com/jeffersongoncalves/git-worktree-cli/main/art/jeffersongoncalves-git-worktree-cli.png)](https://raw.githubusercontent.com/jeffersongoncalves/git-worktree-cli/main/art/jeffersongoncalves-git-worktree-cli.png)

git-worktree-cli
================

[](#git-worktree-cli)

CLI tool to audit git worktrees in a repository and report whether each worktree's branch has already been merged into the main branch. Includes a `clean` command to remove merged worktrees and keep the workspace tidy.

Built with [Laravel Zero](https://laravel-zero.com) and modeled on the other CLIs in this monorepo.

Requirements
------------

[](#requirements)

- PHP `^8.2`
- `git` available on `PATH`
- A git repository with at least one linked worktree

Install
-------

[](#install)

### Global (recommended)

[](#global-recommended)

```
composer global require jeffersongoncalves/git-worktree-cli
```

The binary `git-worktree` will be on your `PATH` as long as Composer's global `vendor/bin` is in it.

### From source

[](#from-source)

```
git clone https://github.com/jeffersongoncalves/git-worktree-cli.git
cd git-worktree-cli
composer install
```

Usage
-----

[](#usage)

```
# Audit the current directory (the default command)
git-worktree

# Audit a specific repo
git-worktree check /path/to/repo

# Force a specific main branch (otherwise auto-detected)
git-worktree check --main=develop

# Only show worktree branches that are NOT merged
git-worktree check --only-unmerged
```

### Add a worktree

[](#add-a-worktree)

```
# Existing local branch — creates /-
git-worktree add feature

# Branch with a slash — uses the suffix after the last "/"
# (feature/foo → /-foo)
git-worktree add feature/foo

# Existing remote branch — auto-tracks origin/
git-worktree add hotfix/login

# Brand-new branch from the auto-detected main (skip prompt)
git-worktree add my-new-feature --yes

# Custom base ref + custom target directory
git-worktree add my-feat --from=develop --target=/tmp/wt-myfeat

# Skip the network check (use only local refs)
git-worktree add my-feat --no-fetch
```

Resolution order: existing local branch → existing remote branch (creates a tracking branch) → new branch from `--from` or the auto-detected main.

### Clean merged worktrees

[](#clean-merged-worktrees)

```
# Preview — doesn't touch anything
git-worktree clean --dry-run

# Prompt to confirm, then remove
git-worktree clean

# Skip confirmation + also delete the local branch
git-worktree clean --yes --delete-branch

# Force removal (worktrees with dirty state, branches with -D)
git-worktree clean --yes --delete-branch --force

# Only remove branches directly merged (exclude squash/rebase detection)
git-worktree clean --strict
```

### List worktrees

[](#list-worktrees)

```
git-worktree list-worktrees
```

### Keep the CLI up to date

[](#keep-the-cli-up-to-date)

When installed from the released PHAR, self-update from the terminal:

```
git-worktree self-update          # download and install the latest release
git-worktree self-update --check  # only check, don't install
```

When installed via Composer, use Composer to update:

```
composer global update jeffersongoncalves/git-worktree-cli
```

How the merge check works
-------------------------

[](#how-the-merge-check-works)

For each linked worktree (the main worktree and bare repos are skipped) the tool inspects the branch checked out in that worktree and compares it to the main branch:

1. If the worktree is detached or on the main branch itself, it is skipped.
2. If branch tip equals main tip → **same as main**.
3. If branch tip is an ancestor of main (direct/fast-forward/merge commit) → **merged**.
4. Otherwise `git cherry main branch` is used to detect **squash/rebase merges** — if every commit on the branch has an equivalent patch on main, the branch is considered merged.
5. Anything else is reported as **not merged**.

`ahead/behind` counts come from `git rev-list --left-right --count`between the branch and the main branch.

Main branch detection
---------------------

[](#main-branch-detection)

In order of priority:

1. `--main=` flag if provided and the ref exists
2. The remote default branch (`origin/HEAD`)
3. Conventional names: `main`, `master`, `develop`, `trunk`

Validation
----------

[](#validation)

The command fails fast when:

- The target path is not a git repository
- The repository has no linked worktrees (only the main checkout)
- The main branch cannot be resolved

Development
-----------

[](#development)

```
composer install
composer test       # Pest tests + Pint lint
composer lint       # Auto-fix style
composer build      # Build the PHAR into builds/git-worktree
```

The PHAR is emitted at `builds/git-worktree`. The `build.yml` workflow rebuilds and commits it back to `main` on every push, using the latest git tag as the embedded version.

Fresh git repositories used by the test suite are created under `tests/tmp/` (which is gitignored).

Release
-------

[](#release)

1. Merge changes to `main` — CI builds a fresh `builds/git-worktree`against the latest tag and commits it back.
2. Create a new GitHub release (tag `X.Y.Z`, no `v` prefix).
3. The `publish-phar.yml` workflow attaches `git-worktree.phar` to the release and `update-changelog.yml` updates `CHANGELOG.md` + `version.txt`.

The `self-update` command pulls the PHAR asset from the latest release.

###  Health Score

41

—

FairBetter than 87% of packages

Maintenance93

Actively maintained with recent releases

Popularity6

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~3 days

Total

7

Last Release

33d ago

Major Versions

v0.0.5 → 1.0.02026-05-07

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/411493?v=4)[Jefferson Gonçalves](/maintainers/jeffersongoncalves)[@jeffersongoncalves](https://github.com/jeffersongoncalves)

---

Top Contributors

[![jeffersongoncalves](https://avatars.githubusercontent.com/u/411493?v=4)](https://github.com/jeffersongoncalves "jeffersongoncalves (32 commits)")

---

Tags

cligitgit-worktreelaravel-zeromerge-checkpharphpworkspace-cleanupworktreecligitmergeworktreebranches

###  Code Quality

TestsPest

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/jeffersongoncalves-git-worktree-cli/health.svg)

```
[![Health](https://phpackages.com/badges/jeffersongoncalves-git-worktree-cli/health.svg)](https://phpackages.com/packages/jeffersongoncalves-git-worktree-cli)
```

###  Alternatives

[symfony/console

Eases the creation of beautiful and testable command line interfaces

9.8k1.1B13.1k](/packages/symfony-console)[nunomaduro/collision

Cli error handling for console/command-line PHP applications.

4.6k348.7M10.3k](/packages/nunomaduro-collision)[nunomaduro/termwind

It's like Tailwind CSS, but for the console.

2.5k260.6M359](/packages/nunomaduro-termwind)[wp-cli/wp-cli

WP-CLI framework

5.1k18.5M386](/packages/wp-cli-wp-cli)[wp-cli/php-cli-tools

Console utilities for PHP

68327.0M372](/packages/wp-cli-php-cli-tools)[projektgopher/whisky

A simple CLI tool for managing a project's git hooks across multiple members.

241337.0k21](/packages/projektgopher-whisky)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
