Guía Definitiva de Git

Guía definitiva de Git: cheat sheet en español con comandos esenciales para configuración, ramas, merges, rebase y remotos, diseñada para flujos de trabajo limpios y productividad en desarrollo a medida.

4 sept 2025 • 4 min read • Q2BSTUDIO Team

Inteligencia-Artificial-

Git Cheat Sheet Definitivo por Q2BSTUDIO. Si buscas una guía clara, directa y lista para usar sobre los comandos esenciales de Git, aquí tienes un resumen completo pensado para desarrolladores y equipos que crean aplicaciones a medida y software a medida, con foco en buenas prácticas, flujos de trabajo limpios y productividad. En Q2BSTUDIO somos especialistas en desarrollo de software multiplataforma, inteligencia artificial, ciberseguridad, servicios cloud aws y azure, servicios inteligencia de negocio, ia para empresas, agentes IA y power bi, llevando la ingeniería de software y la automatización al siguiente nivel para tu organización.

Configuración inicial

Configurar nombre y correo para que se adjunten a tus commits y tags:

git config --global user.name Danny_Adams

git config --global user.email mi_correo@dominio.com

Iniciar un proyecto

Crear un repositorio local:

git init [directorio]

Clonar un repositorio remoto:

git clone [url]

Añadiendo cambios

Añadir un archivo al staging:

git add [archivo]

Añadir todos los archivos modificados al staging:

git add .

Comitear archivos en staging:

git commit -m mensaje_de_commit

Añadir cambios de archivos ya rastreados y comitear en una sola orden:

git commit -am mensaje_de_commit

Conceptos básicos

- main: rama de desarrollo por defecto

- origin: remoto por defecto

- HEAD: referencia a tu commit o rama actual

- HEAD^: padre de HEAD

- HEAD~4: cuatro generaciones por encima de HEAD

Ramas

Listar ramas locales:

git branch

Crear una nueva rama:

git branch [nueva_rama]

Cambiar a una rama y actualizar el directorio de trabajo:

git checkout [rama]

Crear y cambiar a una nueva rama:

git checkout -b [nueva_rama]

Eliminar una rama ya fusionada:

git branch -d [rama]

Eliminar una rama esté o no fusionada:

git branch -D [rama]

Añadir una etiqueta al commit actual:

git tag [nombre_tag]

Fusiones y estrategias de merge

Fusionar la rama a en b:

git checkout b

git merge a

Usa la opción --no-ff para evitar fast forward y crear un commit de merge, preservando el contexto de la rama de feature, facilitando revertir como bloque y manteniendo un historial visual más claro.

Ejemplo visual simplificado

Con fast forward: A - B - C - D en main

Con no ff: A - B - C - D - E con un commit de merge que deja claro el origen de la feature

Fusionar aplastando todos los commits en uno solo:

git merge --squash a

Rebase

Rebase de una rama feature sobre main para integrar cambios de main y mantener el historial limpio:

git checkout feature

git rebase main

Rebase interactivo de los últimos 3 commits:

git rebase -i HEAD~3

Deshacer y mover cambios

Mover o renombrar un archivo y añadirlo al staging:

git mv [ruta_actual] [ruta_nueva]

Eliminar un archivo del working directory y del staging:

git rm [archivo]

Eliminar solo del staging:

git rm --cached [archivo]

Ver un commit anterior en modo solo lectura:

git checkout [ID_commit]

Crear un nuevo commit que revierte cambios de un commit concreto:

git revert [ID_commit]

Volver a un commit anterior borrando commits posteriores:

git reset [ID_commit]

Usa --hard para descartar también cambios del espacio de trabajo solo si entiendes el impacto

Revisión del repositorio

Listar archivos nuevos o modificados aún sin commit:

git status

Mostrar historial de commits en una línea:

git log --oneline

Mostrar cambios no preparados en staging:

git diff

Mostrar diferencias entre dos commits:

git diff [ID_commit_1] [ID_commit_2]

Stashing

Guardar cambios modificados y en staging:

git stash

Guardar con comentario:

git stash save comentario

Stash parcial por archivo o fragmentos:

git stash -p

Listar stashes:

git stash list

Reaplicar sin eliminar:

git stash apply

Reaplicar el stash en índice 2 y eliminarlo:

git stash pop stash@{2}

Mostrar resumen de diferencias del stash 1 y usar -p para ver el diff completo:

git stash show stash@{1}

Sincronización con remotos

Añadir un repositorio remoto:

git remote add [alias] [url]

Ver conexiones remotas:

git remote

Eliminar un remoto:

git remote remove [alias]

Renombrar un remoto:

git remote rename [viejo] [nuevo]

Traer todos los branches del remoto sin fusionar:

git fetch [alias]

Traer un branch específico:

git fetch [alias] [rama]

Traer y fusionar con tu copia local:

git pull

Actualizar con rebase para mantener historial lineal:

git pull --rebase [alias]

Enviar tu contenido local al remoto:

git push [alias]

Enviar a un branch específico:

git push [alias] [rama]

Este cheat sheet está diseñado para que recuerdes rápido los comandos clave de Git y mantengas un flujo de trabajo profesional, ya sea que construyas aplicaciones a medida o gestiones productos complejos con equipos distribuidos. Si quieres acelerar tus proyectos con una base técnica sólida, en Q2BSTUDIO te acompañamos de extremo a extremo en desarrollo de software a medida y modernización de procesos. Descubre cómo transformamos tus ideas en productos escalables en nuestra página de software a medida y aplicaciones a medida, y potencia tu ciclo de vida de desarrollo con nuestra automatización de procesos para equipos de ingeniería.

A BREAK?

Play for a moment before you go

OUR SERVICES

How we can help you

Artificial intelligence

AI agents, chatbots, and intelligent assistants that automate tasks and serve your customers 24/7 to improve the efficiency of your business.

More info

Software Development

Web, mobile, and desktop applications, intranets, e-commerce, SaaS, and management platforms designed for your company's specific needs.

More info

Cloud services

Migration, infrastructure, managed hosting, high availability, and security on Microsoft Azure and Amazon Web Services to help your business scale without limits.

More info

Cybersecurity and pentesting

Security audits, penetration testing and protection of applications, data and infrastructure on-premise and cloud, with ethical hacking and regulatory compliance.

More info

Business Intelligence

Dashboards and data analysis with Power BI: we integrate your sources, design dashboards and KPIs and turn your data into decisions.

More info

Process automation

We automate repetitive tasks and connect your applications with n8n, Power Automate, Make, and RPA, eliminating manual work and increasing productivity.

More info

Training for Companies

We train your teams in technology with criteria: web development, databases, Git, best practices and security, automation with n8n, artificial intelligence for companies and creation of AI solutions with Azure AI Foundry.

More info

Code Auditing

We audit the code that you, your team or an AI create: we tell you what is good and what to improve, we secure it and make it ready for production, web or app.

More info

AI Image Generation

We create for you the images that your business needs with artificial intelligence: product, networks, advertising, illustration and avatars. You tell us what you want and we deliver it ready to use.

More info

AI Video Generation

We create videos with artificial intelligence for you: promotional, networking, virtual presenters, dubbing and animations. You tell us the idea and we will deliver it assembled and ready to publish.

More info

AI Conversational Avatars

We create conversational avatars with AI – digital humans with a face and voice – that serve your customers and teams with the knowledge of your company, on your website, interactive monitors, WhatsApp or Teams.

More info

Online Marketing and AI

Google Ads, Meta Ads, LinkedIn Ads and AI Engine Positioning (GEO/AEO): we attract customers and make your brand appear where they search for you, also on ChatGPT, Gemini and Perplexity.

More info

Do you have a project in mind?

Tell us your vision and we'll turn it into a software solution. Whatever the scope, we make your idea real.

Live Chat