Git Cheatsheet
Referencia rapida de comandos Git y GitHub. Imprimi esta pagina y tenela a mano.
Configuracion
| Comando | Descripción |
|---|---|
| git config --global user.name "Nombre" | Nombre de usuario para todos los repos |
| git config --global user.email "email" | Email para todos los repos |
| git config --global init.defaultBranch main | Branch principal por defecto |
| git config --global core.editor "code --wait" | Editor por defecto (VS Code) |
| git config --list | Mostrar toda la configuracion |
Creación de Repos
| Comando | Descripción |
|---|---|
| git init | Inicializar repo en la carpeta actual |
| git clone <url> | Clonar repositorio remoto |
| git clone <url> <carpeta> | Clonar en carpeta con nombre custom |
| git clone --depth 1 <url> | Clonar shallow (solo ultimo commit) |
Snapshot (add & commit)
| Comando | Descripción |
|---|---|
| git status | Estado actual del working tree |
| git add <archivo> | Agregar archivo al staging |
| git add . | Agregar todos los cambios al staging |
| git add -p | Agregar interactivo (elegir hunk por hunk) |
| git commit -m "mensaje" | Commit con mensaje |
| git commit -am "msg" | Stage + commit (solo archivos tracked) |
| git commit --amend -m "msg" | Modificar el ultimo commit |
| git restore --staged <file> | Sacar archivo del staging area |
| git restore <file> | Deshacer cambios en working directory |
Inspeccion & Diferencias
| Comando | Descripción |
|---|---|
| git log | Historial de commits (detallado) |
| git log --oneline | Historial compacto (una linea) |
| git log --oneline --graph --all | Historial con grafico de branches |
| git show <commit> | Ver detalle de un commit especifico |
| git diff | Cambios en working directory (no staged) |
| git diff --staged | Cambios en staging area |
| git diff <rama1>..<rama2> | Diferencia entre dos branches |
| git blame <archivo> | Quien modifico cada linea |
Branching & Merge
| Comando | Descripción |
|---|---|
| git branch | Listar branches locales |
| git branch <nombre> | Crear nueva branch |
| git checkout -b <nombre> | Crear y cambiar a nueva branch |
| git switch <nombre> | Cambiar a otra branch (moderno) |
| git switch -c <nombre> | Crear y cambiar (forma moderna) |
| git merge <branch> | Fusionar branch en la actual |
| git branch -d <nombre> | Eliminar branch (si fue mergeada) |
| git branch -D <nombre> | Eliminar branch (forzar) |
| git branch -a | Listar todas las branches (local + remoto) |
Remoto (push & pull)
| Comando | Descripción |
|---|---|
| git remote -v | Ver remotos configurados |
| git remote add origin <url> | Agregar remoto llamado "origin" |
| git push -u origin <branch> | Subir branch y setear upstream |
| git push origin <branch> | Subir commits al remoto |
| git pull origin <branch> | Bajar e integrar cambios del remoto |
| git fetch origin | Bajar cambios sin integrar |
| git push origin --delete <branch> | Eliminar branch del remoto |
Stash (Guardar temporal)
| Comando | Descripción |
|---|---|
| git stash | Guardar cambios temporales |
| git stash push -m "descripcion" | Guardar con mensaje descriptivo |
| git stash pop | Restaurar ultimo stash y borrarlo |
| git stash apply | Restaurar sin borrar el stash |
| git stash list | Listar stashes guardados |
| git stash drop | Borrar ultimo stash |
| git stash clear | Borrar todos los stashes |
Tags & Versiones
| Comando | Descripción |
|---|---|
| git tag v1.0.0 | Crear tag liviano |
| git tag -a v1.0.0 -m "Release" | Crear tag anotado con mensaje |
| git tag | Listar tags |
| git push origin v1.0.0 | Subir tag al remoto |
| git push origin --tags | Subir todos los tags |
Convenciones de Commit
| Prefijo | Tipo | Ejemplo |
|---|---|---|
| feat | Nueva funcionalidad | feat: agregar hero section |
| fix | Correccion de bug | fix: corregir responsive en 768px |
| docs | Documentación | docs: actualizar README |
| style | Formato (sin cambio de logica) | style: indentar con 4 espacios |
| refactor | Refactorizacion | refactor: simplificar toggle |
| perf | Performance | perf: lazy load de imagenes |
| test | Tests | test: agregar test sidebar |
| chore | Mantenimiento | chore: actualizar dependencias |
| ci | CI/CD | ci: configurar Actions |
GitHub CLI (gh)
| Comando | Descripción |
|---|---|
| gh repo create <nombre> | Crear repo nuevo desde CLI |
| gh repo clone <repo> | Clonar repo |
| gh pr create --title "T" --body "B" | Crear Pull Request |
| gh pr list | Listar Pull Requests |
| gh pr merge <numero> | Mergear un PR |
| gh issue create | Crear Issue |
| gh issue list | Listar Issues |
| gh issue close <numero> | Cerrar Issue |
| gh browse | Abrir repo en el browser |