Version Control

10 Git Commands Every Developer Should Know

Master the essential Git commands that will make you more productive and confident with version control.

Git is the backbone of modern software development. Whether you're working solo or in a team, these 10 commands will cover 95% of your daily workflow.

1. git status

Always start here. git status shows you what's changed, what's staged, and what branch you're on. Make it a habit to run this before and after every operation.

2. git add -p

Instead of git add ., use git add -p to interactively stage changes. This lets you review each change before committing, keeping your commits focused and clean.

3. git commit -m

Write meaningful commit messages. A good format: type: brief description. For example: fix: resolve login timeout issue.

4. git log --oneline

See your commit history in a compact format. Add --graph for a visual branch representation.

5. git branch -a

List all branches, including remote ones. Use git branch -d name to delete merged branches and keep things tidy.

6. git stash

Need to switch branches but have uncommitted work? git stash saves your changes temporarily. Use git stash pop to restore them.

7. git diff

See exactly what changed. Use git diff --staged to see what's about to be committed.

8. git reset HEAD~1

Undo your last commit while keeping the changes. This is safe and incredibly useful when you commit too early.

9. git rebase -i

Clean up your commit history before merging. Squash, reorder, or edit commits interactively.

10. git cherry-pick

Apply a specific commit from another branch. Perfect for hotfixes that need to go to multiple branches.

Pro Tip

Set up aliases for your most-used commands: git config --global alias.st status, git config --global alias.co checkout.