HeoLab
ToolsBlogAboutContact
HeoLab

Free developer tools with AI enhancement. Built for developers who ship.

Tools

  • JSON Formatter
  • JWT Decoder
  • Base64 Encoder
  • Timestamp Converter
  • Regex Tester
  • All Tools →

Resources

  • Blog
  • What is JSON?
  • JWT Deep Dive
  • Base64 Explained

Company

  • About
  • Contact
  • Privacy Policy
  • Terms of Service

© 2026 HeoLab. All rights reserved.

Tools work in your browser. Zero data retention.

HomeBlogGit Commands Every Developer Needs to Know
Table of Contents▾
  • Daily Workflow
  • Clone a repository
  • See what changed
  • Stage and commit
  • Push / pull
  • Branching
  • Create and switch
  • List branches
  • Rename branch
  • Delete branch
  • Update branch list from remote
  • Viewing History
  • Clean log
  • Who changed this line?
  • Search commits
  • Show a specific commit
  • Undoing Changes
  • Unstage a file (keep changes)
  • Discard changes in working directory
  • Undo last commit (keep changes staged)
  • Undo last commit (keep changes unstaged)
  • Undo last commit (discard changes) ⚠️
  • Revert a commit (safe for public history)
  • I accidentally deleted a file — get it back
  • Stashing
  • Save work in progress
  • List stashes
  • Apply and drop latest stash
  • Apply a specific stash (keep it)
  • Drop a stash
  • Merging vs Rebasing
  • Merge (creates a merge commit, preserves history)
  • Rebase (rewrites history, linear timeline)
  • Interactive rebase — squash, reorder, reword commits
  • Cherry-Picking
  • Apply a specific commit to current branch
  • Cherry-pick a range
  • Cherry-pick without committing (stage only)
  • Aliases (Save Time)
  • Add to ~/.gitconfig
  • Emergency: I Messed Up
  • Find any commit (even deleted ones) — your lifesaver
  • I force-pushed and overwrote remote history
  • Ask a teammate to push their local copy, or restore from reflog
  • Recover a deleted branch
tutorials#git#version-control#developer-tools

Git Commands Every Developer Needs to Know

The complete practical Git reference — from daily workflow commands to advanced rebasing, cherry-picking, and recovering from mistakes.

Trong Ngo
February 23, 2026
4 min read

Git is the one tool every developer uses every day. Yet most developers know only 5-10 commands and panic when something goes wrong. This is the reference I wish I'd had.

Daily Workflow

# Clone a repository
git clone https://github.com/user/repo.git
git clone --depth 1 https://github.com/user/repo.git  # shallow clone (faster)

# See what changed
git status
git diff                    # unstaged changes
git diff --staged           # staged changes

# Stage and commit
git add src/file.ts          # stage specific file
git add src/                  # stage directory
git add -p                    # interactive staging (patch mode)
git commit -m "feat: add login page"
git commit --amend            # modify the last commit (before pushing!)

# Push / pull
git push origin main
git push -u origin feature/my-branch  # set upstream on first push
git pull --rebase             # pull + rebase instead of merge commit

Branching

# Create and switch
git checkout -b feature/my-feature    # create + switch
git switch -c feature/my-feature      # modern equivalent

# List branches
git branch -a                 # all local + remote
git branch -vv                # with tracking and last commit

# Rename branch
git branch -m old-name new-name

# Delete branch
git branch -d feature/done    # safe delete (merged only)
git branch -D feature/done    # force delete
git push origin --delete feature/done  # delete remote branch

# Update branch list from remote
git fetch --prune

Viewing History

# Clean log
git log --oneline --graph --decorate --all

# Who changed this line?
git blame src/file.ts

# Search commits
git log --grep="bug fix"
git log -S "functionName"      # find when a string was added/removed
git log --since="2 weeks ago"
git log --author="Trong"

# Show a specific commit
git show abc1234

Undoing Changes

# Unstage a file (keep changes)
git restore --staged src/file.ts

# Discard changes in working directory
git restore src/file.ts

# Undo last commit (keep changes staged)
git reset --soft HEAD~1

# Undo last commit (keep changes unstaged)
git reset HEAD~1

# Undo last commit (discard changes) ⚠️
git reset --hard HEAD~1

# Revert a commit (safe for public history)
git revert abc1234

# I accidentally deleted a file — get it back
git restore src/deleted-file.ts

Stashing

# Save work in progress
git stash
git stash push -m "WIP: login form"
git stash push --include-untracked

# List stashes
git stash list

# Apply and drop latest stash
git stash pop

# Apply a specific stash (keep it)
git stash apply stash@{2}

# Drop a stash
git stash drop stash@{1}

Merging vs Rebasing

# Merge (creates a merge commit, preserves history)
git checkout main
git merge feature/my-feature

# Rebase (rewrites history, linear timeline)
git checkout feature/my-feature
git rebase main

# Interactive rebase — squash, reorder, reword commits
git rebase -i HEAD~3           # last 3 commits
git rebase -i main             # all commits since branching

Cherry-Picking

# Apply a specific commit to current branch
git cherry-pick abc1234

# Cherry-pick a range
git cherry-pick abc1234^..def5678

# Cherry-pick without committing (stage only)
git cherry-pick --no-commit abc1234

Aliases (Save Time)

# Add to ~/.gitconfig
git config --global alias.st status
git config --global alias.co checkout
git config --global alias.lg "log --oneline --graph --decorate --all"
git config --global alias.undo "reset --soft HEAD~1"
git config --global alias.cleanup "!git fetch -p && git branch -vv | grep gone | awk '{print \$1}' | xargs git branch -D"

Emergency: I Messed Up

# Find any commit (even deleted ones) — your lifesaver
git reflog
git checkout abc1234     # restore to that state

# I force-pushed and overwrote remote history
# Ask a teammate to push their local copy, or restore from reflog

# Recover a deleted branch
git reflog | grep 'branch-name'
git checkout -b branch-name abc1234

git reflog records every HEAD change for 90 days. Almost every git mistake is recoverable if you haven't run git gc (garbage collection).

Related Articles

How AI is Changing Developer Tools in 2025

4 min read

10 Regex Patterns Every Developer Should Know

1 min read

How to Format and Validate JSON Like a Pro

2 min read

Back to Blog

Table of Contents

  • Daily Workflow
  • Clone a repository
  • See what changed
  • Stage and commit
  • Push / pull
  • Branching
  • Create and switch
  • List branches
  • Rename branch
  • Delete branch
  • Update branch list from remote
  • Viewing History
  • Clean log
  • Who changed this line?
  • Search commits
  • Show a specific commit
  • Undoing Changes
  • Unstage a file (keep changes)
  • Discard changes in working directory
  • Undo last commit (keep changes staged)
  • Undo last commit (keep changes unstaged)
  • Undo last commit (discard changes) ⚠️
  • Revert a commit (safe for public history)
  • I accidentally deleted a file — get it back
  • Stashing
  • Save work in progress
  • List stashes
  • Apply and drop latest stash
  • Apply a specific stash (keep it)
  • Drop a stash
  • Merging vs Rebasing
  • Merge (creates a merge commit, preserves history)
  • Rebase (rewrites history, linear timeline)
  • Interactive rebase — squash, reorder, reword commits
  • Cherry-Picking
  • Apply a specific commit to current branch
  • Cherry-pick a range
  • Cherry-pick without committing (stage only)
  • Aliases (Save Time)
  • Add to ~/.gitconfig
  • Emergency: I Messed Up
  • Find any commit (even deleted ones) — your lifesaver
  • I force-pushed and overwrote remote history
  • Ask a teammate to push their local copy, or restore from reflog
  • Recover a deleted branch

Related Articles

How AI is Changing Developer Tools in 2025

4 min read

10 Regex Patterns Every Developer Should Know

1 min read

How to Format and Validate JSON Like a Pro

2 min read