Git Workflow
Flujo de trabajo con Git y GitHub
Branches
| Branch | Propósito | Deploy |
|---|---|---|
main |
Producción | Automático a vps-deploy |
develop |
Staging (opcional) | Automático a vps-dev |
feature/* |
Desarrollo de features | - |
fix/* |
Bugfixes | - |
hotfix/* |
Fixes urgentes en prod | Directo a main |
Flujo Básico
1. Crear branch desde main
git checkout main
git pull origin main
git checkout -b feature/nueva-funcionalidad
2. Desarrollar y commitear
git add .
git commit -m "feat(scope): descripción"
3. Push y crear PR
git push -u origin feature/nueva-funcionalidad
gh pr create --base main
4. Review y merge
# Después de aprobación
gh pr merge --squash
Conventional Commits
Formato: tipo(scope): descripción
Idioma: Siempre en inglés
Tipos
| Tipo | Cuándo usar |
|---|---|
feat |
Nueva funcionalidad |
fix |
Corrección de bug |
docs |
Solo documentación |
style |
Formato (no afecta lógica) |
refactor |
Cambio de código sin fix ni feature |
test |
Agregar o corregir tests |
chore |
Mantenimiento, dependencias |
Ejemplos
# Feature nueva
git commit -m "feat(api): add user authentication endpoint"
# Bug fix
git commit -m "fix(ui): correct button alignment on mobile"
# Documentación
git commit -m "docs(readme): update installation instructions"
# Refactor
git commit -m "refactor(services): extract validation logic"
# Tests
git commit -m "test(auth): add unit tests for login flow"
# Dependencias
git commit -m "chore(deps): update fastapi to 0.104.0"Scope (opcional)
El scope indica qué parte del código se afecta: - api, ui, auth, db, config, etc.
Pull Requests
Crear PR
# Con gh CLI
gh pr create --title "feat(api): add user endpoint" --body "
## Summary
- Added GET /api/v1/users endpoint
- Added user validation
## Test plan
- [ ] Unit tests pass
- [ ] Manual testing done
"Template de PR
## Summary
[Breve descripción de los cambios]
## Changes
- Change 1
- Change 2
## Test plan
- [ ] Tests pass locally
- [ ] Manual testing completed
## Screenshots (si aplica)Review
# Ver PRs pendientes
gh pr list
# Checkout de un PR
gh pr checkout 123
# Aprobar
gh pr review 123 --approve
# Solicitar cambios
gh pr review 123 --request-changes --body "Please fix..."Merge Strategies
Squash Merge (Preferido)
Combina todos los commits en uno solo. Mantiene el historial limpio.
gh pr merge 123 --squashMerge Commit
Mantiene todos los commits. Útil para features grandes.
gh pr merge 123 --mergeResolución de Conflictos
# Actualizar main
git checkout main
git pull origin main
# Volver a feature branch
git checkout feature/mi-feature
# Rebase sobre main
git rebase main
# Resolver conflictos si hay
# Editar archivos con conflictos
git add .
git rebase --continue
# Push forzado (necesario después de rebase)
git push --force-with-leaseComandos Útiles
# Ver estado
git status
# Ver historial
git log --oneline -10
# Ver diferencias
git diff
git diff --staged
# Descartar cambios locales
git checkout -- .
# Stash
git stash
git stash pop
# Ver branches
git branch -a
# Eliminar branch local
git branch -d feature/vieja
# Eliminar branch remota
git push origin --delete feature/vieja.gitignore
Archivos que NUNCA se deben commitear:
# Environments
.env
.env.local
*.env
# Python
__pycache__/
*.py[cod]
venv/
.venv/
# Node
node_modules/
dist/
.next/
# IDE
.idea/
.vscode/
*.swp
# Local
LOCAL-AGENT-CONTEXT.md
*.local