Essential Git Commands for Developers
It does not matter if you write Python, JavaScript, Rust or COBOL, if you work in software, you use Git. It is the tool you are going to use the most in your career, and yet many developers only know git add . and git push.
In this article I teach you the Git commands that you really need to master, organized from basic to advanced, with practical examples that you can use today.
Initial configuration (only once)
Before starting, configure your identity:
git config --global user.name "Tu Nombre"
git config --global user.email "tu@email.com"
This is what will appear in each commit you do. If you work with different emails (personal vs work), you can skip --global and configure it by repository.
Bonus: Set up a default editor for commit messages:
git config --global core.editor "code --wait" # VS Code
The basic daily flow
Start a repository
git init # Crear un nuevo repo
git clone <url> # Clonar uno existente
See the current state
git status # Ver archivos modificados
git status -s # Versión corta
Adding changes to staging
git add archivo.js # Agregar un archivo específico
git add . # Agregar todo
git add -p # Agregar interactivamente (muy útil)
The flag -p (patch) allows you to review each change before adding it. Use it when you have many changes and want to make smaller and more specific commits.
Commit
git commit -m "feat: agregar login" # Commit con mensaje
git commit -am "fix: corregir typo" # Add + commit (solo archivos tracked)
git commit --amend # Modificar el último commit
Pro tip: Use Conventional Committees for clear messages:
feat:new functionalityfix:bug correctiondocs:documentationrefactor:code change without changing functionality
Up changes
git push # Subir al remote
git push -u origin main # Primera vez (establece upstream)
git push --force-with-lease # Force push seguro
▁Nunca Never use git push --force in shared branches. If you need to force, use --force-with-lease that verifies that no one else has uploaded changes.
Working with branches
Branches are the basis of teamwork. Learn to use them well.
Create and change branches
git branch # Ver ramas locales
git branch -a # Ver todas (incluye remotas)
git branch feature/login # Crear rama
git checkout feature/login # Cambiar a la rama
git checkout -b feature/login # Crear y cambiar en un comando
git switch feature/login # Alternativa moderna a checkout
git switch -c feature/login # Crear y cambiar (moderno)
Merging branches
git checkout main # Cambiar a main
git merge feature/login # Fusionar feature/login en main
git merge --no-ff feature/login # Merge sin fast-forward (mantiene historial)
Removing branches
git branch -d feature/login # Eliminar rama local (si ya fue mergeada)
git branch -D feature/login # Eliminar forzado
git push origin --delete feature/login # Eliminar rama remota
Rescue Commands (these will save your life)
View the history
git log # Historial completo
git log --oneline # Una línea por commit
git log --oneline -10 # Últimos 10 commits
git log --graph --oneline --all # Visualizar ramas
Undoing local changes
git checkout -- archivo.js # Descartar cambios en un archivo
git restore archivo.js # Alternativa moderna
git restore --staged archivo.js # Quitar del staging (sin perder cambios)
Stash: save changes temporarily
You have uncommited changes but need to change branches urgently:
git stash # Guardar cambios
git stash push -m "wip: login" # Guardar con mensaje
git stash list # Ver stashes guardados
git stash pop # Recuperar el último stash
git stash apply stash@{2} # Aplicar un stash específico
git stash drop # Eliminar el último stash
Rest: going back in time
git reset --soft HEAD~1 # Deshacer último commit (mantiene cambios en staging)
git reset --mixed HEAD~1 # Deshacer último commit (mantiene cambios sin staging)
git reset --hard HEAD~1 # Deshacer último commit (BORRA todo)
Z Care with --hard: changes are permanently lost.
Reverse: Undo a commit safely
Unlike reset, revert creates a new commit that undoes the changes:
git revert abc123 # Revertir un commit específico
git revert HEAD # Revertir el último commit
It uses reverse when the commit has already been pushed and shared with the team.
See differences
git diff # Cambios no staged
git diff --staged # Cambios en staging
git diff main..feature/login # Diferencia entre ramas
git diff HEAD~3 # Cambios de los últimos 3 commits
Bonus: Aliases to be more productive
Add these aliases to your configuration:
git config --global alias.st "status -s"
git config --global alias.co "checkout"
git config --global alias.br "branch"
git config --global alias.cm "commit -m"
git config --global alias.lg "log --oneline --graph --all"
git config --global alias.undo "reset --soft HEAD~1"
Now you can use:
git st # En lugar de git status -s
git co main # En lugar de git checkout main
git lg # Log bonito con gráfico
git undo # Deshacer último commit
Summary: the 10 commands you will use most
git status: See what changedgit add -p: Add changes selectivelygit commit -m "": Commit with messagegit push: Up changesgit pull: Bringing Remote Changesgit checkout -b: Create and change branchesgit merge: Merging branchesgit stash: save changes temporarilygit log --oneline: View historygit diff: See differences
Frequently asked questions
What are the most important Git commands?
The daily ones: add, commit, push, pull, status, branch, checkout and merge. With mastering those covers 90% of the real work.
How do I undo a change or commit in Git?
It depends: git restore to rule out unsave changes, git reset to move the HEAD, and git revert to undo an already published commit without rewrite history. I cover them in the rescue command section above.
Do you need to master Git to get a job as a developer? Yes, it is non-negotiable. Git is one of the skills I take for granted in my guide to stand out in tech in 2026, and goes hand in hand with improve as a programmer.
Conclusion
Git seems intimidating at first, but once you master these commands, it becomes second nature. My advice: don't try to memorize everything. Use this guide as a reference and practice with real projects.
If something goes wrong (and it will go wrong), remember: almost everything in Git is reversible. Breathe, look for the right command, and move on.
Do you have a favorite command that I did not mention? Share it on my networks.
Was this guide useful? Share it with that friend who is still afraid of Git. And follow me for more content on development and tools.