Skip to main content

gws delete

Delete a git worktree and cleanup associated resources.

Usage

gws delete <worktree> [options]

Output:

ℹ This will permanently delete worktree: 'feature-auth' from project 'myapp':
ℹ - Git worktree directory: ./.worktrees/feature-auth
✔ Delete? … yes
✔ Worktree deleted from 1 repo(s)

Note: This command can be run from anywhere using the -p [project] option.


Arguments

ArgumentDescriptionRequired
<worktree>Worktree name to be deletedYes

Options

OptionDescriptionDefault
-p, --project <name>Project nameAuto-detected from current directory
-y, --yesSkip confirmation promptfalse
--delete-branchAlso delete the associated git branchfalse

Examples:

# Skip confirmation
gws delete -w feature-auth -y

# Keep branch
gws delete -w feature-auth --keep-branch

Multirepo Behavior

When running gws delete in a multirepo setup, the command deletes the worktree from each repository.

Project Structure Before Delete

myapp/                          # Parent directory
├── .worktrees/ # Shared worktrees folder
│ └── feature-auth/ # Worktree to delete
│ ├── api/
│ │ └── src/
│ └── app/
│ └── src/
├── api/ # Git repo 1
│ ├── .git/
│ └── src/
└── app/ # Git repo 2
├── .git/
└── src/

Deleting Worktree

cd myapp
gws delete -w feature-auth
# or from any directory
gws delete -w feature-auth -p myapp

Output:

ℹ This will permanently delete worktree: 'feature-auth' from project 'myapp':
ℹ - Git worktree directory: ./.worktrees/feature-auth
✔ Delete? … yes
✔ Worktree deleted from 2 repo(s)

What happens:

  1. Deletes .worktrees/feature-auth/ from the parent directory
  2. Removes the git worktree registration from each repo
  3. Deletes branch env/feature-auth from each repo (unless --delete-branch is omitted)
  4. Git commit history is preserved in all repositories

Common Errors

Worktree is Currently Deployed

Error:

✖ Cannot delete worktree 'feature-auth'
✖ Deployment is currently running in namespace 'myapp-feature-auth'
✖ Please stop the deployment first with: gws down -w feature-auth

Solution:

# Stop the deployment first
gws down -w feature-auth

# Then delete the worktree
gws delete -w feature-auth

Worktree Not Found

Error:

✖ Worktree 'feature-auth' not found
✖ No worktree directory exists at .worktrees/feature-auth

Solution:

# Check existing worktrees
gws status

# Verify worktree name
git worktree list

See Also