Git for Developers: The Commands You'll Use Every Day

You know git add, git commit, git push. But what about the commands that actually save you in a real project?

Branching Like a Pro

# Create and switch in one step
git checkout -b feature/user-auth

# List all branches (including remote)
git branch -a

# Delete a merged branch
git branch -d feature/user-auth

# Force-delete an unmerged branch
git branch -D old-experiment

Stashing Work in Progress

# Save uncommitted changes and clean working tree
git stash push -m "half-done login form"

# List stashes
git stash list
# stash@{0}: On main: half-done login form

# Apply without removing
git stash apply stash@{0}

# Apply AND remove
git stash pop

Undoing Mistakes

# Undo the last commit but keep changes staged
git reset --soft HEAD~1

# Undo the last commit and unstage
git reset HEAD~1

# Nuclear option: destroy last commit AND changes
git reset --hard HEAD~1

# Revert a specific commit (safe for shared branches)
git revert abc1234

# Fix the last commit message or add a forgotten file
git add forgotten-file.py
git commit --amend --no-edit

Rebasing (Cleaner History)

# Rebase your branch onto main
git checkout feature/api
git rebase main

# Interactive rebase — squash, reorder, edit last 5 commits
git rebase -i HEAD~5

In the interactive editor, change pick to:
- s (squash) — combine with previous commit
- r (reword) — change commit message
- d (drop) — delete the commit

Useful Aliases

git config --global alias.st    "status -sb"
git config --global alias.lg    "log --oneline --graph --decorate"
git config --global alias.undo  "reset HEAD~1"
git config --global alias.aliases "config --get-regexp alias"

Finding Who Broke What

# Blame a specific line
git blame -L 42,52 app.py

# Binary search for when a bug was introduced
git bisect start
git bisect bad                  # current commit is broken
git bisect good v1.0.0          # this tag was fine
# Git checks out commits in between — test each one
git bisect good   # or
git bisect bad
# Git finds the exact commit that introduced the bug
git bisect reset

Git mastery is what separates junior from senior developers. Learn these and you'll be the person your team asks for help.