The essential commands that every developer should know

Git and GitHub are fundamental tools for any modern developer. Git enables local version control, while GitHub facilitates collaboration and code hosting in the cloud. In this article, we present you a practical guide with the essential commands to work efficiently with both.

✨ 1. Initial configuration

Before you start working with Git, you need to set up your identity:

git config --global user.name "Your name"
git config --global user.email "yourname@example.com"

If you will use token authentication on GitHub:

git config --global credential.helper cache

πŸ“ 2. Create or Clone Repositories

git init # Start a new local repository
git clone https://github.com/usuario/repositorio.git  # Clone a repository from Github

πŸ“„ 3. File tracking

git status            # Checks the repository status
git add archivo.txt   # Add the file to staging area
git add .             # Add all files changed

πŸ“† 4. Commits

git commit -m "Mensaje"        # Create a new commit with a message
git commit -am "Mensaje"       # Add and commit all tracked files

βš–οΈ 5. Synchronization with GitHub (Remote Repository)

git remote add origin https://github.com/usuario/repositorio.git  # Associate local repository to GitHub
git push -u origin main       # Send commits to branch β€œmain” on GitHub
git pull origin main          # Download and merge changes from GitHub

πŸ”Ί 6. Branches

git branch                    # List of local branches
git branch nueva-rama         # Create new local branch
git checkout nueva-rama       # Switch to another branch
git checkout -b nueva-rama    # Create and switch to new branch
git push -u origin nueva-rama # Upload the branch to GitHub and attach it

πŸ” 7. Pull Requests and Collaboration

Although pull requests are handled in the GitHub interface, you can start the process with branch

  1. Create a new branch with git checkout -b feature-x

  2. Upload the branch with git push origin feature-x

  3. Opens a Pull Request in GitHub from that branch to main

❌ 8. Reverse changes

git reset archivo.txt               # Remove staging file
git checkout -- archivo.txt         # Reverse local changes
git revert ID_COMMIT                #  Reverse a created commit with a new one
git reset --hard HEAD~1             # Delete the last commit (risky)

πŸ“ƒ 9.Changes history

git log                   # Show the commit history
git log --oneline         # History in one line

πŸ€– 10. Additional utilities

git stash                 # Save the temporal changes
git stash pop             # Restore the saved changes
git tag v1.0              # Create a new label

🧹 11. Cleaning and Maintenance

git rm --cached archivo.txt        # Delete the trace file without deleting it
git clean -n                       # Muestra archivos a eliminar
git clean -f                       # Displays files to be deleted
git clean -fd                      # Includes folders
git clean -fx                      # Includes ignored files

Mastering these essential Git and GitHub commands will allow you to manage your projects professionally and collaboratively. Over time, you can explore advanced features such as workflows, GitHub actions, branch protection, and CI/CD automations.

For more information: