10 Git Commands Every Developer Must Know
By JobQNA Team • Updated: Jan 15, 2025
Git is the industry standard for version control. Whether you are working on a solo project or in a large team at FAANG, messing up a merge conflict can be scary. This guide covers the essential commands that will save you in production.
1. Starting a Repository (Init & Clone)
Every project starts here. You either create a new folder or download an existing project from GitHub/GitLab.
git init
# Clone (download) an existing repo
git clone https://github.com/user/project.git
2. Staging and Committing Changes
Git doesn't track changes automatically; you have to tell it what to save. This is a two-step process: add (stage) and commit (save).
git add index.html
# Add all changes (Warning: Check .gitignore first!)
git add .
# Save with a message
git commit -m "Fixed login bug"
3. The "Oh No!" Command (Undo)
Made a mistake in your last commit message? Or forgot to add a file? You don't need to delete everything.
git commit --amend -m "New correct message"
4. Interview Question: Merge vs Rebase
This is the #1 Git interview question. Both commands combine changes from one branch to another, but they do it differently.
- Git Merge: Creates a new "merge commit". It preserves history exactly as it happened. Good for main branches.
- Git Rebase: Moves your entire branch to the tip of the main branch. It creates a linear history (cleaner logs) but can be dangerous if shared with others.
git merge feature-branch
# Clean history (Rewrites history)
git rebase main
5. Checking Status and Logs
Before running any command, always check the status of your files.
git status
# See commit history (one line per commit)
git log --oneline
git push --force unless you are 100% sure. It can delete your team's work!
Conclusion
Git is a powerful tool, but it requires practice. Start using the command line instead of GUI tools to build muscle memory. For a quick reference of all flags and options, bookmark our Git Cheat Sheet.