DevOps & Version Control

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.

# Initialize a new git repo
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).

# Add a specific file
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.

# Change the last commit message
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.

# Safe option (Preserves history)
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.

# See changed files
git status

# See commit history (one line per commit)
git log --oneline
Warning: Never use 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.