September 7, 2026
Do you know Git? Of course you do! Today, I’ve got a few of my favorite Git commands for...

Most developers learn Git by rote—clone, add, commit, push—and then spend months or years stumbling through their workflows without realizing how much time they're leaving on the table. If you've ever lost a commit, wrestled with merge conflicts, or spent hours tracking down a regression, you know that a few well-placed Git commands can mean the difference between a productive afternoon and a frustrating one. Here are some commands that, once you internalize them, become indispensable parts of your daily toolkit.
Picture this: you're mid-feature, with half-written code on your screen, when a critical bug report lands in your inbox. You need to switch branches now, but you don't want to commit incomplete work. Enter git stash. Running git stash tucks your current changes away, leaving you with a clean working directory. When you're ready to return, git stash pop retrieves those changes and removes them from the stash stack. If you want to keep them around for later, git stash apply leaves them in place.
The stash command becomes even more powerful with git stash -u, which includes untracked files, or git stash --keep-index, which preserves staged changes while stashing the rest. These variations handle real-world scenarios that the basic command alone cannot.
One of the most nerve-wracking moments in Git is realizing you've lost work—perhaps you did a hard reset, or deleted a branch by accident. Before you panic, reach for git reflog. This command shows you a log of every reference update in your repository, including commits that are no longer visible on any branch. By finding the commit hash, you can checkout or create a branch pointing to it, recovering your work in seconds.
Equally valuable for debugging is git bisect. When you're hunting down which commit introduced a bug, manual inspection becomes untenable in large codebases. Bisect performs a binary search, checking out commits automatically and asking you to test each one. You mark commits as good or bad, and Git narrows down the culprit in logarithmic time. What might have taken hours becomes a matter of minutes.
git cherry-pick lets you apply a specific commit from one branch onto another, without merging the entire branch. This is invaluable when you've fixed a bug on a feature branch and need that fix on main, or when you've crafted a perfect commit that belongs in multiple places. The command is straightforward: cherry-pick accepts a commit hash and applies its changes to your current branch.
On the subject of commits, git commit --amend is a simple but transformative command. Made a typo in your commit message? Forgot to stage a file? Amend lets you modify the most recent commit, replacing it entirely. This rewrites history, so use it only on commits that haven't been pushed to shared branches—but within that constraint, it's a clean way to maintain accurate commit messages without cluttering your history with "fix typo" follow-ups.
The default git log output is functional but sparse. Learn to use git log --oneline --graph --decorate --all to visualize your branch structure at a glance. Adding --author or --since filters narrows results to relevant history. These flags turn an opaque list of commits into a readable narrative of your project's evolution.
Finally, when you need a fresh start, git clean removes untracked files from your working directory. Use git clean -n first to preview what will be deleted, then git clean -f to actually remove files. Combine it with -d to clean directories as well. It's a quick way to reset your workspace when you've accumulated experimental files you no longer need.
Further reading: https://dev.to/sylwia-lask/10-git-commands-youll-wish-you-knew-earlier-4fcp
You've probably had this exact moment. You ask an AI a math question. It lays out the steps...
Sep 7, 2026