Git Pie: A Arte Ancestral do Versionamento 🥧 Help

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?

Compartilha

Cria

Cria

Referencia

Referencia

Repositório Base

.git

Worktree 1

Worktree 2

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

HotfixFeatureMainHotfixFeatureMainCriar worktree featureCriar worktree hotfixDesenvolvimentoCorreção urgenteMerge hotfixMerge feature

Cenários Comuns

+------------------------+ | CASOS DE USO | | | | • Feature paralela | | • Hotfix urgente | | • Build separado | | • Review de PR | | • Testes isolados | +------------------------+

Boas Práticas

Recomendações

WorktreesOrganizaçãoManutençãoWorkflowEstrutura claraNomes descritivosPrune regularLock quando inativoBranch por worktreePropósito definido

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

ProblemasConflitosPerformanceReferênciasBranch ocupadoLock ativoDisco cheioMuitos worktreesBranch deletadoWorktree órfão

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

Criar

Build

Success

Fail

PR Recebido

Worktree Review

Testes

Merge

Cleanup

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

IDEVSCodeJetBrainsEclipseMulti-rootWorkspaceProject groupsVCS rootsWorking setsGit support

Próximos Passos

Tópicos Relacionados

22 abril 2025