Most developers use Git every single day.
But many of them use only five commands:
git add . git commit -m "changes" git push git pull git status Everything works perfectly until someone introduces a bug, deletes a branch, creates a merge conflict, or accidentally commits the wrong file.
That's when Git becomes more than a version control tool.
It becomes a lifesaver.
Here are 15 powerful Git commands that can save you hours of frustration and help you become a more confident developer.
1. Recover Lost Commits With Git Reflog
Accidentally lost a commit?
Don't panic.
git reflog Git reflog records recent changes to references in your local repository, including movements of HEAD.
Once you identify the commit you need, create a recovery branch:
git branch recovery <commit-hash> Your lost work may still be recoverable.
This is one Git command every developer should know.
2. Find the Commit That Introduced a Bug
Imagine your application worked perfectly last week, but now it's broken.
There are 100 commits between the working and broken versions.
Instead of checking every commit manually, use Git bisect.
git bisect start git bisect bad git bisect good <working-commit> Test each selected revision and mark it:
git bisect good Or:
git bisect bad Git uses a binary search approach to narrow down the problematic commit.
When finished:
git bisect reset You've just turned a potentially long debugging session into a systematic investigation.
3. Temporarily Save Unfinished Work
You're working on a feature when your teammate asks you to fix an urgent bug.
But your current work isn't ready to commit.
Use:
git stash When you're ready to continue:
git stash pop You can also inspect saved changes:
git stash list Remember that untracked files are not included by default. Use git stash -u when you intentionally want to include them.
4. Fix Your Last Commit Message
Made a spelling mistake in your commit message?
git commit --amend -m "Correct commit message" This creates a replacement commit.
Be careful when amending commits that have already been shared with other developers, because it rewrites commit history.
5. Discover Who Changed a Line of Code
Found a confusing piece of code?
git blame app.py Git displays the commit and author associated with each line.
This is useful for understanding the history behind a change.
Despite its name, Git blame should be used for investigation, not blaming teammates.
6. Visualize Your Entire Git History
Instead of scrolling through a long commit history, use:
git log --oneline --graph --all --decorate You'll get a compact visualization of branches, commits and merges.
Example:
* 8a91f20 Fix authentication issue * 7b82e10 Improve API response | * 6c73d40 Add dashboard |/ * 5d64c30 Initial implementation This is especially useful when working with multiple branches.
7. Undo a Commit Without Rewriting History
Need to reverse a problematic commit on a shared branch?
git revert <commit-hash> Git creates a new commit that reverses the selected changes.
Unlike history-rewriting approaches, this preserves the existing commit history.
For shared repositories, this is often a safer option.
8. Bring a Specific Commit Into Another Branch
Sometimes you don't need to merge an entire branch.
You only need one specific commit.
git cherry-pick <commit-hash> Git applies the changes introduced by that commit to your current branch.
This can be useful for applying selected bug fixes or transferring specific improvements.
9. Create Better Commits With Interactive Staging
Imagine modifying ten files while working on two different features.
Instead of committing everything together:
git add -p Git allows you to review and stage individual sections of your changes.
This helps create smaller, more meaningful commits.
Your teammates will appreciate it during code reviews.
10. Search Through Your Project's History
Want to know when a function was introduced or removed?
git log -S "function_name" The -S option searches for commits that change the number of occurrences of a particular string.
This is extremely useful when investigating unfamiliar codebases.
Enjoying These Git Tips?
Knowing individual commands is useful, but understanding how Git works makes those commands much more powerful.
I've published a dedicated learning resource for developers who want to move beyond basic Git commands.
📘 Git Mastery — From Zero to Expert
The Complete Guide to Git, GitHub & GitLab.
For beginners, software developers, students and aspiring DevOps engineers who prefer structured learning.
Starting at just $4.99.
Combine it with practical experiments in your own repositories to build confidence with Git.
11. Work on Multiple Branches Simultaneously
Constantly switching branches can interrupt your workflow.
Git worktree lets you check out branches into separate directories.
git worktree add -b feature-login ../feature-login Now you can work on your new feature in a separate directory without disturbing your existing working directory.
This is particularly useful when handling multiple tasks.
12. Compare Changes Between Branches
Before merging a feature branch, inspect the differences:
git diff main...feature-branch This shows the changes between the branches' merge base and the feature branch.
It helps you understand what a feature introduces before reviewing or merging it.
13. Preview Files Git Would Delete
Want to remove untracked files?
Always preview the operation first:
git clean -n This shows which untracked files would be removed without actually deleting them.
Understanding the impact of a command before executing it is an important engineering habit.
14. Create Useful Git Aliases
Tired of typing long commands?
git config --global alias.st status git config --global alias.co checkout git config --global alias.br branch git config --global alias.lg "log --oneline --graph --all" Now you can use:
git st git br git lg Small workflow improvements can save significant time over repeated use.
15. Understand What You're About to Commit
Before creating a commit, inspect your staged changes:
git diff --staged This helps catch:
- Debugging statements
- Accidental file modifications
- Unnecessary code changes
- Sensitive information
- Incorrect configurations
Never commit blindly.
Reviewing your own changes is one of the simplest ways to improve code quality.
The Git Cheat Sheet Every Developer Should Bookmark
| Command | Purpose |
|---|---|
git reflog | Investigate recent reference changes |
git bisect | Find commits that introduced bugs |
git stash | Temporarily save changes |
git commit --amend | Replace the last commit |
git blame | Investigate line-level history |
git log --graph | Visualize commit history |
git revert | Reverse committed changes |
git cherry-pick | Apply selected commits |
git add -p | Stage selected changes |
git log -S | Search historical code changes |
git worktree | Work in multiple working directories |
git diff | Compare changes |
git clean -n | Preview untracked file removal |
git config | Customize Git settings |
git diff --staged | Review staged changes |
Save this table. Your future self might thank you.
Git Is Just the Beginning
Knowing Git makes you a more productive developer.
But combining Git with programming, containerization, infrastructure automation and problem-solving can make you a much more capable engineer.
I've published a collection of affordable digital books for developers who prefer structured, self-paced learning.
📚 The Complete Developer Learning Library
🌿 Git Mastery — From Zero to Expert
Strengthen your version control knowledge and learn Git, GitHub and GitLab.
Starting at $4.99
🐍 Mastering Python — The Complete Developer's Masterclass
Build programming and automation skills using Python.
Starting at $7
🐹 Mastering Go — The Complete Developer's Masterclass
Explore Go for backend development and cloud-native engineering.
Starting at $5.99
🐳 Docker Mastery — From Zero to Certified
Understand containers, images and modern application environments.
Starting at $4
☸️ CKA Complete Study Guide
Develop your Kubernetes administration knowledge and support your CKA preparation.
Starting at $13.99
☁️ Terraform Associate Exam Crash Course
Explore Infrastructure as Code and infrastructure automation.
Starting at $4
⚙️ DevOps Complete Pack
Explore a broader collection of DevOps learning resources.
$12.99
🧠 The Sharp Mind — Mastering Critical Thinking
Strengthen analytical thinking, decision-making and problem-solving skills.
Starting at $8
📚 Browse the Entire Book Collection
These are my own paid educational resources. Every purchase supports my work as an independent educational content creator.
Choose the book that matches your learning goals. For certification-specific resources, check the current official exam objectives before purchasing.
Try This 7-Day Git Challenge
Create a separate practice repository and complete these challenges.
| Day | Challenge |
|---|---|
| 1 | Create branches and merge them |
| 2 | Create and resolve a merge conflict |
| 3 | Recover a lost commit using reflog |
| 4 | Practise interactive staging |
| 5 | Find an intentionally introduced bug using bisect |
| 6 | Revert and cherry-pick commits |
| 7 | Review and document your entire Git workflow |
By the end of the challenge, you'll have practical experience with several Git operations that go beyond the basics.
You can also refer to these excellent free resources:
Reading helps you understand. Practice helps you remember.
Final Thoughts
You don't need to memorize every Git command.
You need to understand what Git is doing behind the scenes.
The difference between a beginner and an experienced Git user often becomes visible when something goes wrong.
A beginner might panic.
An experienced developer investigates the history, understands the available recovery options and chooses an appropriate solution.
Learn Git before you desperately need it.
Your Turn 💬
What is the one Git command that saved you from a serious mistake?
Have you ever accidentally deleted important work, broken a branch or spent hours resolving a merge conflict?
Share your experience in the comments.
Let's make this article a collection of practical Git knowledge that every developer can learn from.
If this article helped you, bookmark it, share it with your developer friends and follow me for more practical content about Git, programming, Docker, Kubernetes and DevOps.
Happy coding! 🚀

