Seamlessly switch between Git branches with isolated development environments using Dev Containers
As developers, we often struggle with:
- Context switching between branches/features
- Dependency conflicts between different tasks
- Time wasted reconfiguring environments
- "Works on my machine" issues
DevTree solves these problems by combining Git worktrees with dedicated Dev Containers for each branch.
✨ Branch-specific environments: Each branch gets its own isolated Dev Container
⚡ Instant context switching: Move between tasks with a single command
🔒 Dependency isolation: Prevent version conflicts between features
🚀 Parallel development: Run multiple branches simultaneously on different ports
💾 Automatic configuration: Dynamic port allocation and environment setup
🔗 VS Code integration: Direct workspace switching
DevTree creates a symbiotic relationship between:
- Git worktrees (physical directory copies of your repository)
- Dev Containers (Docker-based development environments)
Each branch exists in its own directory with a custom-configured Dev Container that has:
- Unique port assignments
- Isolated dependencies
- Branch-specific configurations
- Preserved runtime state
- .NET 6.0 SDK
- Git
- Docker Engine
- Dev Containers CLI (
npm install -g @devcontainers/cli) - VS Code (recommended)
# Clone repository
git clone https://github.com/yourusername/devtree.git
# Build the tool
cd devtree
dotnet publish -c Release -o ./publish
# Add to PATH (Linux/macOS)
echo 'export PATH="$PATH:'$(pwd)'/publish"' >> ~/.bashrc
source ~/.bashrc
# Add to PATH (Windows)
[System.Environment]::SetEnvironmentVariable(
"Path",
[System.Environment]::GetEnvironmentVariable("Path", [System.EnvironmentVariableTarget]::User) +
";C:\path\to\devtree\publish",
[System.EnvironmentVariableTarget]::User)mkdir my-project
cd my-project
git init
touch Dockerfile # Add your base Dockerfile
devtree initdevtree create --branch feature-auth# Start development environment
devtree start feature-auth
# Open in VS Code
code $(devtree path feature-auth)# Switch to another feature
devtree switch --branch payment-integration
# List all environments
devtree listdevtree remove --branch feature-authsequenceDiagram
participant D as DevTree CLI
participant G as Git
participant DC as Dev Containers
participant Dkr as Docker
D->>G: devtree create feature-auth
G-->>D: Creates worktree
D->>DC: Generate devcontainer.json
D->>Dkr: Build container
D->>Dkr: Start container
D->>User: Ready on port 3001
User->>D: devtree switch payment-feature
D->>Dkr: Stop feature-auth container
D->>G: Checkout payment-feature
D->>Dkr: Start payment-feature container
D->>User: Ready on port 3002
classDiagram
class DevTreeCli {
+Main(args: string[])
}
class WorktreeManager {
+CreateWorktree(branch: string)
+RemoveWorktree(branch: string)
+GetWorktreePath(branch: string) string
}
class DevContainerManager {
+StartContainer(branch: string)
+StopContainer(branch: string)
+GenerateConfig(branch: string, port: int)
}
class PortManager {
-_allocatedPorts: HashSet<int>
+AcquirePort() int
+ReleasePort(port: int)
}
class StateManager {
+CurrentBranch: string
+BranchPorts: Dictionary<string, int>
+SaveState()
+LoadState()
}
DevTreeCli --> WorktreeManager
DevTreeCli --> DevContainerManager
DevTreeCli --> PortManager
DevTreeCli --> StateManager
DevContainerManager --> PortManager
devtree create --branch experiment --dockerfile Dockerfile.experiment# Reserve specific port
devtree create --branch docs --port 8080
# List used ports
devtree ports# Set branch-specific variables
devtree env set feature-auth API_KEY=special_key
# View current environment
devtree env list feature-auth# Save container state
devtree snapshot create feature-auth
# Restore from snapshot
devtree snapshot restore feature-authCustomize DevTree behavior via .devtree/config.yaml:
worktrees:
root: worktrees # Worktree directory
prefix: "branch-" # Directory prefix
devcontainers:
base_config: .devcontainer/base.json # Shared configuration
port_range: [3000, 4000] # Allocatable ports
auto_start: true # Start container on create
docker:
cleanup: true # Remove images on branch delete
shared_volumes: # Volumes to share between branches
- common-cache- OS: Windows 10/11, macOS 10.15+, Linux (kernel 5.0+)
- Disk Space: 1GB + project requirements
- Memory: 4GB+ (8GB recommended for multiple containers)
We welcome contributions! Please follow these steps:
- Fork the repository
- Create a feature branch (
git checkout -b feature/your-feature) - Commit your changes (
git commit -am 'Add amazing feature') - Push to the branch (
git push origin feature/your-feature) - Open a Pull Request
- Basic branch management
- Dev Container integration
- VS Code extension
- CI/CD pipeline templates
- Performance optimizations
- Windows Terminal integration
- Remote development support
DevTree is licensed under the MIT License - see the LICENSE file for details.
Stop context switching, start developing!
Give your branches the isolated environments they deserve with DevTree.