Referencia completa de comandos Git — desde configuración hasta ramas, fusión y flujos avanzados.
git config --global user.name "Name"Configuración e instalaciónSet global author name
ej. git config --global user.name "Jane Doe"
git config --global user.email "email"Configuración e instalaciónSet global author email
ej. git config --global user.email "[email protected]"
git config --listConfiguración e instalaciónList all configuration settings
git config --global core.editor "code"Configuración e instalaciónSet VS Code as default editor
git config --global alias.<alias> <cmd>Configuración e instalaciónCreate a command alias
ej. git config --global alias.st status
git initConfiguración e instalaciónInitialize a new local repository
git init <dir>Configuración e instalaciónInitialize a repo in a specific directory
ej. git init my-project
git clone <url>Configuración e instalaciónClone a remote repository
ej. git clone https://github.com/user/repo.git
git clone <url> <dir>Configuración e instalaciónClone into a specific folder
ej. git clone https://github.com/user/repo.git my-dir
git statusStaging y conceptos básicosShow working tree status
git status -sStaging y conceptos básicosShort/compact status output
git add <file>Staging y conceptos básicosStage a specific file
ej. git add README.md
git add .Staging y conceptos básicosStage all changes in current directory
git add -pStaging y conceptos básicosInteractively stage hunks of changes
git commit -m "msg"Staging y conceptos básicosCommit staged changes with a message
ej. git commit -m "feat: add login page"
git commit -am "msg"Staging y conceptos básicosStage tracked files and commit in one step
git commit --amenddestructivoStaging y conceptos básicosModify the most recent commit (message or content)
git diffStaging y conceptos básicosShow unstaged changes
git diff --stagedStaging y conceptos básicosShow staged changes (vs last commit)
git diff <branch1>..<branch2>Staging y conceptos básicosCompare two branches
ej. git diff main..feature
git rm <file>Staging y conceptos básicosRemove a file from working tree and index
ej. git rm old-file.txt
git rm --cached <file>Staging y conceptos básicosUntrack a file without deleting it
ej. git rm --cached secret.txt
git mv <old> <new>Staging y conceptos básicosMove or rename a tracked file
ej. git mv old.js new.js
git branchRamas y fusionesList local branches
git branch -aRamas y fusionesList all branches (local + remote)
git branch <name>Ramas y fusionesCreate a new branch
ej. git branch feature/auth
git checkout <branch>Ramas y fusionesSwitch to an existing branch
ej. git checkout main
git checkout -b <branch>Ramas y fusionesCreate and switch to a new branch
ej. git checkout -b feature/auth
git switch <branch>Ramas y fusionesSwitch branches (modern syntax)
ej. git switch main
git switch -c <branch>Ramas y fusionesCreate and switch (modern syntax)
ej. git switch -c feature/auth
git branch -d <branch>Ramas y fusionesDelete a merged branch
ej. git branch -d feature/auth
git branch -D <branch>destructivoRamas y fusionesForce delete a branch (unmerged too)
ej. git branch -D feature/old
git branch -m <old> <new>Ramas y fusionesRename a branch
ej. git branch -m old-name new-name
git merge <branch>Ramas y fusionesMerge a branch into current branch
ej. git merge feature/auth
git merge --no-ff <branch>Ramas y fusionesMerge with a merge commit (no fast-forward)
git merge --squash <branch>Ramas y fusionesSquash all commits from branch into one staged change
git merge --abortRamas y fusionesAbort an in-progress merge
git remote -vOperaciones remotasList remote connections with URLs
git remote add <name> <url>Operaciones remotasAdd a new remote
ej. git remote add origin https://github.com/user/repo.git
git remote remove <name>Operaciones remotasRemove a remote connection
ej. git remote remove origin
git remote rename <old> <new>Operaciones remotasRename a remote
ej. git remote rename origin upstream
git fetchOperaciones remotasDownload all changes from remote (no merge)
git fetch <remote>Operaciones remotasFetch from a specific remote
ej. git fetch origin
git pullOperaciones remotasFetch and merge changes from remote
git pull --rebaseOperaciones remotasFetch and rebase onto remote branch
git push <remote> <branch>Operaciones remotasPush branch to remote
ej. git push origin main
git push -u origin <branch>Operaciones remotasPush and set upstream tracking
ej. git push -u origin feature/auth
git push --force-with-leasedestructivoOperaciones remotasSafe force push (fails if others pushed)
git push --tagsOperaciones remotasPush all tags to remote
git push origin --delete <branch>destructivoOperaciones remotasDelete a remote branch
ej. git push origin --delete feature/old
git restore <file>destructivoDeshacer cambiosDiscard changes in working directory
ej. git restore index.html
git restore --staged <file>Deshacer cambiosUnstage a file (keep changes)
ej. git restore --staged index.html
git reset HEAD <file>Deshacer cambiosUnstage a file (older syntax)
ej. git reset HEAD index.html
git reset --soft HEAD~1Deshacer cambiosUndo last commit, keep changes staged
git reset --mixed HEAD~1Deshacer cambiosUndo last commit, unstage changes (default)
git reset --hard HEAD~1destructivoDeshacer cambiosUndo last commit, discard all changes
git reset --hard <commit>destructivoDeshacer cambiosReset to a specific commit, discard everything after
git revert <commit>Deshacer cambiosCreate a new commit that undoes a specific commit
ej. git revert a1b2c3d
git revert HEADDeshacer cambiosRevert the most recent commit
git clean -fddestructivoDeshacer cambiosRemove untracked files and directories
git clean -nDeshacer cambiosDry run: show what would be cleaned
git stashGuardar cambiosStash current working directory changes
git stash push -m "msg"Guardar cambiosStash with a descriptive message
ej. git stash push -m "WIP: auth feature"
git stash listGuardar cambiosList all stashes
git stash popGuardar cambiosApply most recent stash and remove it
git stash apply stash@{n}Guardar cambiosApply a specific stash without removing
ej. git stash apply stash@{0}
git stash drop stash@{n}Guardar cambiosDelete a specific stash
ej. git stash drop stash@{0}
git stash cleardestructivoGuardar cambiosRemove all stashes
git stash branch <branch>Guardar cambiosCreate a branch from a stash
ej. git stash branch feature/from-stash
git rebase <branch>Rebase y avanzadoRebase current branch onto another
ej. git rebase main
git rebase -i HEAD~nRebase y avanzadoInteractive rebase for last n commits
ej. git rebase -i HEAD~3
git rebase --continueRebase y avanzadoContinue rebase after resolving conflicts
git rebase --abortRebase y avanzadoAbort an in-progress rebase
git cherry-pick <commit>Rebase y avanzadoApply a specific commit to current branch
ej. git cherry-pick a1b2c3d
git cherry-pick <c1>..<c2>Rebase y avanzadoApply a range of commits
ej. git cherry-pick a1b2c3d..f6e5d4c
git bisect startRebase y avanzadoStart binary search for a bug
git bisect good <commit>Rebase y avanzadoMark a commit as good in bisect
git bisect bad <commit>Rebase y avanzadoMark a commit as bad in bisect
git bisect resetRebase y avanzadoEnd bisect session
git worktree add <path> <branch>Rebase y avanzadoCheck out a branch into a separate directory
git logInspección y registroShow commit history
git log --onelineInspección y registroCompact one-line log
git log --oneline --graph --allInspección y registroVisual branch graph in terminal
git log -n <count>Inspección y registroShow last N commits
ej. git log -n 5
git log --author="name"Inspección y registroFilter commits by author
ej. git log --author="Jane Doe"
git log --since="2 weeks ago"Inspección y registroShow commits since a date
git log -p <file>Inspección y registroShow changes to a specific file over time
ej. git log -p README.md
git log --follow <file>Inspección y registroFollow renames of a file in history
git show <commit>Inspección y registroShow details of a specific commit
ej. git show a1b2c3d
git blame <file>Inspección y registroShow who last modified each line
ej. git blame src/app.tsx
git shortlog -snInspección y registroSummarize commits by author
git reflogInspección y registroShow history of HEAD movements (recovery tool)
git grep "pattern"Inspección y registroSearch working directory for a pattern
ej. git grep "TODO"
git tagEtiquetasList all tags
git tag <name>EtiquetasCreate a lightweight tag
ej. git tag v1.0.0
git tag -a <name> -m "msg"EtiquetasCreate an annotated tag
ej. git tag -a v1.0.0 -m "Release v1.0.0"
git tag -a <name> <commit>EtiquetasTag a past commit
ej. git tag -a v0.9.0 a1b2c3d
git show <tag>EtiquetasShow tag metadata and commit
ej. git show v1.0.0
git push origin <tag>EtiquetasPush a specific tag to remote
ej. git push origin v1.0.0
git push origin --tagsEtiquetasPush all tags to remote
git tag -d <tag>EtiquetasDelete a local tag
ej. git tag -d v1.0.0
git push origin --delete <tag>EtiquetasDelete a remote tag
ej. git push origin --delete v1.0.0
git merge combina dos ramas creando un commit de fusión, preservando el historial completo de ambas ramas. git rebase mueve commits de una rama a otra, reescribiendo el historial para crear un historial de commits lineal y más limpio. Usa merge para ramas públicas y trabajo compartido; usa rebase para limpiar ramas de características locales antes de fusionar.
Usa git reset --soft HEAD~1 para deshacer el último commit manteniendo los cambios en staging. Usa git reset HEAD~1 (o --mixed) para quitar los cambios del staging pero mantenerlos en el directorio de trabajo. Usa git reset --hard HEAD~1 para descartar permanentemente el commit y todos los cambios (operación destructiva).
git fetch descarga cambios del remoto pero NO los fusiona en tu rama actual. Actualiza tus ramas de seguimiento remoto (origin/main). git pull es git fetch + git merge (o git rebase con --rebase). Usa fetch cuando quieras inspeccionar los cambios antes de integrarlos.
Después de una fusión/rebase conflictiva, Git marca los archivos conflictivos con marcadores '<<<<<<', =======, >>>>>>. Abre cada archivo conflictivo, elige manualmente qué cambios conservar, elimina los marcadores, luego pon los archivos resueltos con git add '<'archivo> y completa con git merge --continue o git commit.