Hoja de comandos de Git

Git registra los cambios de tus archivos como una serie de commits en un repositorio. Estos comandos cubren el flujo diario: crear un repo, guardar trabajo, ramificar, fusionar y compartir con un remoto. Mantén esta hoja abierta mientras aprendes.

Actualizado:

ComandoQué hace
git initCreate a new, empty Git repository in the current directory.
git cloneDownload a remote repository and its full history to your machine.
git statusShow changed, staged and untracked files in the working tree.
git addStage changes (files) to be included in the next commit.
git commitRecord staged changes as a new commit with a message.
git logDisplay the commit history of the repository.
git diffShow unstaged or staged differences between states.
git branchList, create or delete branches in the repository.
git checkout / switchSwitch branches or restore files (switch is the modern command).
git mergeJoin another branch's history into the current branch.
git rebaseReapply commits on top of another base commit, rewriting history.
git pullFetch from a remote and merge the changes into the current branch.
git pushUpload local commits to a remote repository.
git stashTemporarily shelve uncommitted changes to reapply later.
git remoteManage the set of remote repositories you track.

Notas

Preguntas frecuentes

¿Cuál es la diferencia entre merge y rebase?
Merge combina historiales con un nuevo commit que tiene dos padres. Rebase reproduce tus commits encima de otra rama, dando una historia lineal pero reescribiendo los IDs de commit.
¿Cómo deshago un commit?
Usa 'git revert <commit>' para añadir un nuevo commit que deshace el cambio (seguro, historial compartido). 'git reset' reescribe la historia y no debe usarse en ramas compartidas.
¿Qué diferencia hay entre git pull y git fetch?
Fetch descarga commits y referencias desde un remoto sin tocar tu árbol de trabajo. Pull hace fetch y luego fusiona o hace rebase de esos cambios en tu rama actual.
¿Cuándo debo usar git stash?
Stash aparta temporalmente los cambios sin commitear para que puedas cambiar de rama o hacer pull limpio, y luego los restauras con 'git stash pop'.