Git Worktrees: Trabalhando com Múltiplos Diretórios
+------------------------+
| Git Worktrees |
| |
| Multiple Workspaces |
| Parallel Development |
| Resource Efficiency |
| |
| Flexible Management |
+------------------------+
Conceitos Básicos
O que são Worktrees?
Estrutura
projeto/
├── .git/
├── main/
│ └── [branch main]
├── feature/
│ └── [branch feature]
└── hotfix/
└── [branch hotfix]
Comandos Essenciais
Operações Básicas
# Criar worktree
git worktree add ../feature feature-branch
# Listar worktrees
git worktree list
# Remover worktree
git worktree remove ../feature
# Mover worktree
git worktree move ../feature ../new-feature
Gerenciamento
# Criar nova branch com worktree
git worktree add -b nova-feature ../feature
# Limpar worktrees inacessÃveis
git worktree prune
# Bloquear worktree
git worktree lock ../feature
Casos de Uso
Desenvolvimento Paralelo
Cenários Comuns
+------------------------+
| CASOS DE USO |
| |
| • Feature paralela |
| • Hotfix urgente |
| • Build separado |
| • Review de PR |
| • Testes isolados |
+------------------------+
Boas Práticas
Recomendações
Configuração
# Alias úteis
git config alias.wt 'worktree'
git config alias.wta 'worktree add'
git config alias.wtl 'worktree list'
git config alias.wtr 'worktree remove'
Troubleshooting
Problemas Comuns
Soluções
# Resolver lock
git worktree unlock ../feature
# Limpar worktrees mortos
git worktree prune
# Forçar remoção
git worktree remove -f ../feature
Workflows Avançados
CI/CD
#!/bin/sh
# Script de build paralelo
for branch in feature/* ; do
git worktree add "../build/${branch##*/}" $branch
(cd "../build/${branch##*/}" && ./build.sh)
done
Automação
Dicas Avançadas
Performance
# Otimizar espaço
git worktree add --detach ../feature
# Checkout otimizado
git worktree add -f --checkout ../feature
Manutenção
+------------------------+
| MANUTENÇÃO |
| |
| • Backup .git |
| • Prune regular |
| • Monitor espaço |
| • Check locks |
| • Clean worktrees |
+------------------------+
Integração com Ferramentas
IDE Support
Próximos Passos
Tópicos Relacionados
Git Branches
Git Performance
22 abril 2025