DEV Community

David Garcia
David Garcia

Posted on

💡 5 comandos de Git poco conocidos que mejorarán tu flujo de trabajo

Git tiene más que commit, merge y checkout. Aquí tienes 5 comandos que pueden hacerte la vida más fácil:

1️⃣ git switch - Cambia de rama sin riesgos

Antes de Git 2.23, git checkout hacía demasiadas cosas: cambiaba de rama, restauraba archivos y más. Ahora, git switch es una opción más clara y segura:

git switch feature-branch  # Cambia a una rama existente
git switch -c nueva-rama   # Crea y cambia a una nueva rama
Enter fullscreen mode Exit fullscreen mode

Ya no hay miedo de sobrescribir archivos por error.

2️⃣ git restore - Revierte cambios sin complicaciones

Para deshacer cambios sin modificar la rama o el historial:

git restore archivo.js         # Descarta cambios no confirmados  
git restore --staged archivo.js # Quita cambios del área de staging  
Enter fullscreen mode Exit fullscreen mode

Evita errores con checkout y reset, separando mejor las operaciones.

3️⃣ git maintenance - Mantén tu repo rápido y limpio

Los repos grandes pueden volverse lentos. git maintenance automatiza la limpieza:

git maintenance start  # Activa el mantenimiento automático  
git maintenance run    # Ejecuta tareas de optimización  
Enter fullscreen mode Exit fullscreen mode

Reduce el tiempo de git status, fetch y log sin esfuerzo.

4️⃣ git sparse-checkout - Trabaja en monorepos sin descargar todo

Si solo necesitas ciertas carpetas de un repo gigante:

git sparse-checkout init  
git sparse-checkout set directorio1/ directorio2/  
Enter fullscreen mode Exit fullscreen mode

Descarga solo lo necesario y ahorra espacio en disco.

5️⃣ git worktree - Trabaja en varias ramas sin cambiar de directorio

Si necesitas trabajar en diferentes ramas sin hacer stash o cambiar de carpeta:

git worktree add ../feature-branch feature-branch  
cd ../feature-branch  
Enter fullscreen mode Exit fullscreen mode

Ideal para revisar código sin afectar tu rama principal.

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more