Snippets

git

8 git code snippets across 1 language. Copy-paste solutions from production code.

8

git

8 snippets

Beautiful One-Line git log as a Global Alias

Set up a global git alias for a colored, graph-aware, one-line git log that makes commit history actually readable.

gitlogalias+2
BEGINNERJun 9, 2026

Find the Bad Commit with git bisect

Use git bisect to binary-search through commits and find the exact one that introduced a bug or test failure.

gitbisectdebugging+2
INTERMEDIATEMay 14, 2026

Recover a Deleted Git Branch with reflog

Use git reflog to find and restore a branch you accidentally deleted with git branch -D or a botched rebase.

gitreflogrecovery+2
INTERMEDIATEMay 2, 2026

Remove Untracked Files Safely with git clean

Use git clean -n to preview what will be deleted, then -fd to actually remove untracked files and empty directories. Without losing work.

gitcleanuntracked+2
INTERMEDIATEJun 17, 2026

Squash the Last N Commits with Interactive Rebase

Use git rebase -i to squash, reorder, edit, or drop the last N commits before pushing or opening a pull request.

gitrebasesquash+2
INTERMEDIATEApr 22, 2026

Undo the Last Git Commit (Keep or Discard Changes)

How to undo the most recent git commit using git reset, with --soft, --mixed, and --hard explained side by side.

gitresetundo+2
BEGINNERApr 10, 2026

Useful git stash Patterns Beyond stash and pop

Stash with a message, stash untracked files, list stashes, apply a specific stash, and stash a single file. The full git stash workflow.

gitstashworkflow+2
BEGINNERMay 22, 2026

Work on Multiple Branches with git worktree

Use git worktree to check out multiple branches simultaneously in separate directories. No more stash-and-switch dance.

gitworktreebranches+2
INTERMEDIATEJun 1, 2026