Git is one of the most used tools in development.
But many developers use only a small part of it —
and avoid the rest because it feels risky.
This guide covers a few essential commands that can save your work and make you more confident using Git.
1. git stash — save your work without committing
Sometimes you're in the middle of something,
but need to switch branches.
Instead of committing unfinished code, you can use:
git stash
This temporarily saves your changes.
Later, you can bring them back with:
git stash pop
2. git reflog — recover lost commits
If you think you lost a commit,
you might still be able to recover it.
git reflog
This shows a history of everything you’ve done.
You can go back to a previous state using:
git checkout <commit>
3. git reset — use with understanding
git reset can be dangerous if used incorrectly.
But it’s also very useful.
There are different types:
-
--soft→ keeps changes staged -
--mixed→ keeps changes but unstaged -
--hard→ deletes everything
Example:
git reset --soft HEAD~1
This removes the last commit but keeps your changes.
4. git cherry-pick — reuse specific commits
Sometimes you don’t want to merge everything —
just one commit.
git cherry-pick <commit>
This applies a specific commit to your current branch.
5. git rebase — rewriting history (use with care)
git rebase is one of the most powerful Git commands —
but also one of the most misunderstood.
It allows you to move or rewrite commits on top of another branch.
Example:
git rebase main
This takes your current branch and applies your commits on top of main.
Why developers use it
- keeps commit history cleaner
- avoids unnecessary merge commits
- makes history easier to read
But be careful
Rebasing can rewrite history.
That means:
- don't rebase shared branches
- avoid it on branches others are using
- use it mainly for local cleanup
Simple way to think about it
👉 merge = combine histories
👉 rebase = rewrite history linearly
Final thoughts
Git is not dangerous.
Not understanding Git is.
Once you learn these commands,
you stop avoiding Git — and start using it properly.
Top comments (0)