DEV Community

Cover image for Git Survival Guide: Commands You Should Actually Understand
Noriuki
Noriuki

Posted on

Git Survival Guide: Commands You Should Actually Understand

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
Enter fullscreen mode Exit fullscreen mode

This temporarily saves your changes.

Later, you can bring them back with:

git stash pop
Enter fullscreen mode Exit fullscreen mode

2. git reflog — recover lost commits

If you think you lost a commit,

you might still be able to recover it.

git reflog
Enter fullscreen mode Exit fullscreen mode

This shows a history of everything you’ve done.

You can go back to a previous state using:

git checkout <commit>
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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>
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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)