Skip to content

Laravel Git Worktree Manager - Create and manage git worktrees for Laravel projects with automatic environment setup for Laravel Herd

License

Notifications You must be signed in to change notification settings

histonedev/wt-tool

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

wt - Laravel Git Worktree Manager

A CLI tool to create and manage git worktrees for Laravel projects with automatic environment setup for Laravel Herd.

Features

  • Create git worktrees with automatic Laravel environment setup
  • Configure .env files with correct APP_URL and DB_DATABASE
  • Auto-install Composer and NPM dependencies
  • Generate new APP_KEY for isolated worktrees (optional)
  • Copy databases between worktrees (MySQL and SQLite)
  • Open worktrees directly in PHPStorm
  • Works seamlessly with Laravel Herd's .test domain convention

Requirements

  • Python 3.7+
  • Git
  • Laravel Herd (for automatic .test domain routing)
  • Composer
  • MySQL CLI tools (optional, for database copying)

Installation

Option 1: Direct download

sudo curl -o /usr/local/bin/wt https://raw.githubusercontent.com/histonedev/wt-tool/main/wt.py
sudo chmod +x /usr/local/bin/wt

Option 2: Clone and symlink

git clone https://github.com/histonedev/wt-tool.git ~/.wt-tool
sudo ln -s ~/.wt-tool/wt.py /usr/local/bin/wt

Option 3: User-local install (no sudo)

mkdir -p ~/.local/bin
curl -o ~/.local/bin/wt https://raw.githubusercontent.com/histonedev/wt-tool/main/wt.py
chmod +x ~/.local/bin/wt
# Add to PATH if needed: export PATH="$HOME/.local/bin:$PATH"

Usage

Run commands from within your Laravel project directory.

Create a Worktree

# Create worktree from existing branch
wt add feature/payments

# Create worktree with a new branch
wt add -b feature/new-feature

# Create worktree and copy database
wt add --db feature/payments

# Create worktree with a fresh APP_KEY
wt add --key feature/payments

# Combine flags
wt add -b --db --key feature/payments

# Specify custom folder name
wt add feature/payments my-custom-folder

Remove a Worktree

# Remove worktree only
wt remove project-payments

# Remove worktree and drop database
wt remove --db project-payments

List Worktrees

wt list

Open in PHPStorm

wt open project-payments

Version

wt --version

How It Works

  1. Worktree Creation: Creates a git worktree in the parent directory of your main project
  2. Environment Setup: Copies .env from main project and updates:
    • APP_URL to http://<folder-name>.test
    • DB_DATABASE to match folder name
  3. Dependencies: Automatically runs composer install and npm install
  4. APP_KEY (with --key flag): Generates a fresh application key
  5. Database (with --db flag): Copies MySQL database or SQLite file from source

Directory Structure

~/Sites/
├── my-laravel-app/           # Main project
├── my-laravel-app-feature/   # Worktree for feature branch
└── my-laravel-app-hotfix/    # Worktree for hotfix branch

URL Convention

Worktrees follow Laravel Herd's convention:

  • Folder: my-laravel-app-feature
  • URL: http://my-laravel-app-feature.test

Database Support

The tool auto-detects your database driver from .env:

  • MySQL/MariaDB: Uses mysqldump to copy databases (requires mysql and mysqldump CLI tools)
  • SQLite: Copies the database/database.sqlite file

License

MIT License - see LICENSE for details.

About

Laravel Git Worktree Manager - Create and manage git worktrees for Laravel projects with automatic environment setup for Laravel Herd

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages