🌿Developer

The Git Commands You Actually Use (And the Ones You Pretend to Understand)

A no-nonsense guide to the 20 Git commands that cover 95% of real work. Plus honest explanations of rebase, cherry-pick, and reflog — the ones developers fake knowing.

9 min readJanuary 8, 2026By FreeToolKit TeamFree to read

Most Git tutorials start with init and end somewhere around branching, leaving you to figure out the actually useful parts on your own. This isn't that tutorial.

The Core Commands (Daily Use)

  • git status — always run this first. Shows what's changed, what's staged, what's untracked.
  • git add -p — add changes interactively, chunk by chunk. Dramatically better than git add . for crafting clean commits.
  • git commit -m 'message' — commit staged changes. Write commit messages in imperative mood: 'Fix login bug' not 'Fixed login bug'.
  • git log --oneline --graph -- visually shows branch history. Add --all to see all branches.
  • git diff — shows unstaged changes. git diff --staged shows what's about to be committed.

Branch Management (Weekly Use)

  • git checkout -b feature/name — create and switch to a new branch in one command.
  • git branch -d branch-name — delete a merged branch. -D forces deletion even if unmerged.
  • git merge --no-ff feature/name — merge with a merge commit, preserving branch history. --no-ff prevents fast-forward for cleaner history on significant merges.
  • git push origin branch-name -- explicitly push a branch to remote. First time: git push -u origin branch-name sets the upstream.

The Powerful Ones People Avoid

git rebase -i HEAD~3 — interactive rebase. Lets you squash, reorder, reword, or drop the last 3 commits before pushing. Use this to clean up messy WIP commits into something presentable. Essential for clean pull request history.

git cherry-pick abc1234 — apply a single commit from another branch to the current one. When you've fixed a bug on a feature branch that needs to go to main without the whole feature. More precise than merging entire branches.

git reflog — your safety net. Shows every HEAD movement in the repo, including after resets and rebases. If you accidentally deleted commits, they're in reflog for 90 days. git checkout the commit SHA to recover them.

git bisect — binary search through commit history to find when a bug was introduced. git bisect start, mark good/bad commits, and Git automates the search. Finding the exact commit that introduced a regression in a codebase with 3,000 commits takes minutes instead of hours.

The Aliases Worth Setting Up

Add to ~/.gitconfig

[alias]
  lg = log --oneline --graph --all
  st = status -s
  co = checkout
  undo = reset --soft HEAD~1
  aliases = config --get-regexp alias

Three Git Mistakes Most Developers Make

  • Committing everything with git add . — you end up committing debug logs, temporary files, and unrelated changes. Use git add -p (patch mode) to review each change before staging.
  • Force pushing to shared branches — git push --force on main or develop overwrites other people's commits. Never. If you need to force push: only on your own feature branches, and use --force-with-lease which fails if someone else pushed since your last pull.
  • Unclear commit messages — 'fix stuff', 'wip', 'updates' are meaningless in a blame or log. Six months later, you'll be the one confused by your own commits. 'Fix null pointer in UserService.getProfile when email is missing' takes 10 extra seconds to write and saves 20 minutes of debugging.

Frequently Asked Questions

What's the difference between git merge and git rebase?+
Both integrate changes from one branch into another, but they create different history. Merge creates a new 'merge commit' that joins two branch histories, preserving the full timeline of when things happened. Rebase replays your commits on top of the target branch, creating a linear history as if you started your branch from the latest commit. Rebase produces cleaner history but rewrites commits (changing their SHA), which is why the rule exists: never rebase branches that others are working on. Use merge for main/develop branches; rebase for cleaning up your local feature branch before a pull request.
How do I undo the last git commit without losing my changes?+
git reset --soft HEAD~1 — this undoes the commit but keeps your changes staged. Your work is intact; only the commit is removed. Three modes: --soft (changes stay staged), --mixed (default — changes unstaged but files unchanged), --hard (changes discarded entirely — use with caution, this is destructive). If you've already pushed the commit: git revert HEAD instead, which creates a new commit that undoes the changes without rewriting history.
What is git stash and when should I use it?+
Stash temporarily shelves uncommitted changes so you can switch branches without committing half-finished work. git stash saves current changes, git stash pop restores them. It's most useful when you're mid-feature and someone asks you to quickly fix something on a different branch. Caveat: stash is a stack — multiple stashes are tracked with indices (stash@{0}, stash@{1}). Run git stash list to see what's stashed. Don't leave things in stash indefinitely; it's easy to forget what's there.
What does git fetch do vs git pull?+
git fetch downloads changes from the remote but doesn't apply them to your working branch — you see what's new but your code is unchanged. git pull does fetch + merge (or fetch + rebase if configured). Fetch first, review, then merge manually is safer — you see what's coming before integrating it. Many developers configure pull to rebase: git config --global pull.rebase true, which keeps history cleaner by avoiding unnecessary merge commits when pulling.

🔧 Free Tools Used in This Guide

FT

FreeToolKit Team

FreeToolKit Team

We build free browser-based tools and write practical guides without the fluff.

Tags:

gitdeveloperversion-controltutorial