Git version control workflow diagram

Git Manual: Essential Version Control Commands

A quick-reference guide to the Git commands you will use every day: initializing a repository, staging and committing changes, branching, merging, undoing mistakes with reset, and connecting to a remote like GitHub. Available in Spanish and English.

Manual de comandos de Git

Estos son los comandos más usados en Git, explicados de forma clara y con ejemplos prácticos para quienes están empezando a usar control de versiones.

git help
Muestra la ayuda general de Git. También puedes combinarlo con otro comando, por ejemplo git help commit, para ver la documentación específica de ese comando.
git init
Inicializa un repositorio nuevo en la carpeta actual. Le indica a Git que comience a monitorear los archivos del proyecto para que los cambios se puedan reconocer y versionar.
git status
Muestra el estado actual del repositorio: qué archivos fueron modificados, cuáles están preparados (staged) para el commit y cuáles todavía no están siendo rastreados.
git add <archivo>
Agrega un archivo específico al área de preparación (staging area) para incluirlo en el próximo commit. Todos los archivos que necesites deben agregarse antes de confirmar los cambios.
git add -A
Agrega en un solo paso todos los archivos nuevos, modificados y eliminados al área de preparación, listos para el próximo commit.
git commit -m "mensaje"
Confirma (commit) los cambios preparados. El "mensaje" describe qué se hizo en ese commit, para poder identificarlo entre los demás. Debe ser lo más descriptivo posible y evitar tildes o caracteres especiales, ya que pueden causar problemas de codificación en algunos entornos.
git commit --amend -m "nuevo mensaje"
Permite corregir el mensaje (o el contenido) del último commit, útil cuando te equivocaste antes de compartirlo con el equipo.
git log
Muestra el historial completo de commits del proyecto, con autor, fecha y mensaje de cada uno, y permite navegar entre ellos.
git checkout <rama>
Permite movernos entre ramas ya existentes en el repositorio.
git checkout master
Nos lleva al último commit de la rama principal en la que estemos situados.
git reset --soft
Deshace el último commit pero conserva los cambios en el área de preparación; no altera el código de tus archivos.
git reset --mixed
No altera el código de tus archivos, pero borra el registro del commit y quita los cambios del área de preparación.
git reset --hard
Borra por completo tanto el historial del commit como el código asociado a él. Úsalo con cuidado: esta acción no se puede deshacer.
git branch <rama>
Crea una nueva rama con el nombre indicado, en la cual puedes trabajar para hacer pruebas o desarrollar una función sin afectar la rama principal.
git branch -d <rama>
Elimina una rama local que ya no necesitas, por ejemplo después de haber trabajado o hecho pruebas en ella.
git checkout -b <rama>
Crea una nueva rama y nos movemos a ella en un solo paso.
git merge <rama>
Fusiona (absorbe) los cambios de la rama indicada dentro de la rama en la que estés situado. Primero debes ubicarte en la rama que recibirá los cambios y luego correr el comando.
git remote add origin <url>
Conecta un repositorio ya creado en GitHub (u otro proveedor) con el repositorio que tienes localmente.
git remote remove origin
Desconecta el proyecto local del repositorio remoto en la nube.
git push origin master -f
Fuerza la subida de tus cambios al repositorio remoto, sobrescribiendo su historial. Úsalo con precaución, ya que puede eliminar cambios de otros colaboradores.
touch .gitignore
Crea un archivo .gitignore donde puedes listar los archivos que Git debe ignorar, para que no se suban al repositorio.

Git command manual

These are the most commonly used Git commands, explained clearly with practical examples for anyone getting started with version control.

git help
Shows Git's general help. A useful way to use it is by combining it with another command, for example git help commit, to get information specific to that command.
git init
Initializes a new repository in the current folder. It tells Git to start scanning your project so that future changes are recognized and tracked.
git status
Shows the current status of your project: which files and other elements are pending before you can make your commit.
git add <file>
Adds a specific file to the changes that will be included in your next commit. Every file you need has to be added before you commit.
git add -A
Stages every new, modified and deleted file in a single step, ready for the next commit.
git commit -m "message"
Commits and records the staged changes. The "message" is a short description of the commit so it can be identified among the others. It should be as descriptive as possible, and should avoid accented characters or special symbols, since they can cause encoding issues in some environments.
git commit --amend -m "new message"
Lets you correct the message (or contents) of the last commit, in case something was wrong before it was shared with the team.
git log
Gives you a report of every commit made in your project and lets you navigate through them.
git checkout <branch>
Lets you switch between existing branches.
git checkout master
Moves you to the latest commit on the branch you are currently on.
git reset --soft
A simple reset that undoes the last commit but keeps your changes staged; it does not touch your code.
git reset --mixed
Does not touch your code, but it removes the commit record and unstages the changes.
git reset --hard
Wipes out both the commit record and the code changes tied to it. Use it carefully — this action cannot be undone.
git branch <branch>
Creates another branch to work on, for tests or new features, without affecting the main branch.
git branch -d <branch>
After you have worked or run tests and no longer want to keep a branch, this command lets you delete it.
git checkout -b <branch>
Lets you move to another branch while also creating it with the name given on the command line.
git merge <branch>
Lets you absorb another branch. First locate yourself on the branch that will absorb the other one, then run the command, replacing <branch> with the name of the branch to be merged in.
git remote add origin <url>
Connects your local repository with a repository already created on GitHub (or another provider).
git remote remove origin
Disconnects your local project from the remote repository in the cloud.
git push origin master -f
Force-pushes your commit to the remote repository, overwriting its history. Use with caution, since it can wipe out other collaborators' changes.
touch .gitignore
Lets you create a list of files to ignore, so they do not get uploaded to the repository.