#git
100 snippets tagged with #git
Undo Last Git Commit (Soft and Hard)
Git commands to undo the last commit while keeping changes staged, unstaged, or fully discarded.
Best for: Fixing a commit with wrong files or message
Git Rebase Workflow Example
Step-by-step git rebase workflow to keep feature branches up to date with main branch cleanly.
Best for: Keeping feature branches linear with main
Git Cherry-Pick Commits Example
Apply specific commits from one branch to another using cherry-pick with conflict resolution.
Best for: Backporting bug fixes to release branches
Squash Multiple Git Commits
Interactive rebase to squash multiple commits into one clean commit before merging a feature branch.
Best for: Cleaning up messy commit history
Git Stash Usage Examples
Save, list, apply, and manage uncommitted changes with git stash for quick context switching.
Best for: Switching branches with uncommitted work
Rename Git Branch (Local and Remote)
Commands to rename a local and remote Git branch including updating tracking references.
Best for: Fixing branch naming convention mistakes
Delete Remote Git Branch
Commands to delete local and remote branches, prune stale references, and clean up merged branches.
Best for: Cleaning up after merged pull requests
Resolve Git Merge Conflicts
Step-by-step guide to identify, resolve, and complete merge conflict resolution in Git.
Best for: Resolving conflicts during branch merges
Git Interactive Rebase Guide
Interactive rebase to reorder, edit, drop, and squash commits for a clean Git history.
Best for: Crafting a clean commit history before merge
Git Revert Commit Safely
Create a new commit that undoes changes from a previous commit without rewriting history.
Best for: Undoing a deployed commit on shared branches
Git Reset and Restore File Changes
Commands to discard, unstage, or restore file changes using git restore and git checkout.
Best for: Discarding experimental changes in files
Git Force Push Safely
Use force-with-lease instead of force push to prevent overwriting teammates' commits on remote.
Best for: Pushing after rebase without overwriting others' work
Git Clone Specific Branch
Clone a specific branch from a remote repository without fetching all branches and history.
Best for: Cloning only a deployment branch for CI/CD
Git Shallow Clone for Large Repos
Shallow clone techniques to reduce download size by limiting commit history depth.
Best for: Speeding up CI/CD pipeline cloning
Git Hooks Pre-Commit Example
Git pre-commit and commit-msg hooks to enforce linting, tests, and commit message conventions.
Best for: Enforcing code quality before commits
Git Bisect to Find a Bug
Use binary search through commit history with git bisect to find the exact commit that introduced a bug.
Best for: Finding which commit introduced a regression
Git Worktree for Multiple Branches
Work on multiple branches simultaneously using git worktree without stashing or switching.
Best for: Reviewing PRs while working on a feature
Git Submodule Management
Add, update, and manage Git submodules for including external repositories in your project.
Best for: Including shared libraries across multiple repos
Git Log Formatting Tricks
Custom git log formats with graphs, filtering by author, date ranges, and file changes.
Best for: Reviewing project history efficiently
Git Tag Management for Releases
Create, list, push, and manage annotated and lightweight tags for version releases.
Best for: Marking release points in project history
Git Reflog Recovery Guide
Use git reflog to recover lost commits, undo hard resets, and restore deleted branches.
Best for: Recovering from accidental git reset --hard
Git Aliases for Productivity
Essential git aliases and config settings to speed up daily git workflow and reduce typing.
Best for: Speeding up daily git workflow
.gitignore Patterns and Templates
Comprehensive .gitignore patterns for Node.js, Python, and general development environments.
Best for: Setting up gitignore for new projects
Git Patch Create and Apply Workflow
Generate and apply git patches to share changes via email or transfer between repositories.
Best for: Sharing changes without push access
Git Blame Investigation Techniques
Use git blame and related tools to trace code authorship and understand change history.
Best for: Finding who introduced a bug
Git Rebase Strategies Guide
Advanced rebase strategies for cleaning history including onto, autosquash, and conflict resolution.
Best for: Cleaning commit history before merging
Advanced Git Diff Techniques
Compare changes between branches, commits, and working tree with filtering and formatting options.
Best for: Reviewing changes before code review
Git Archive and Export Project
Export clean project archives from Git without .git directory for deployment or distribution.
Best for: Creating clean deployment packages
Git Subtree Workflow
Use git subtree to include external repositories as subdirectories without submodule complexity.
Best for: Including shared code without submodule complexity
Git Repository Cleanup and Maintenance
Commands for cleaning untracked files, pruning refs, optimizing repo size, and maintenance tasks.
Best for: Reducing repository size and improving performance
Interactive Rebase — Squash and Reorder
Use git rebase -i to squash, edit, reorder, or drop commits before pushing to clean up history.
Best for: Cleaning commit history before merging a PR
Git Bisect — Find the Commit That Broke It
Use binary search across commits to pinpoint exactly which commit introduced a bug or regression.
Best for: Finding which commit introduced a regression
Git Cherry-Pick — Apply Specific Commits
Cherry-pick single, multiple, or ranges of commits from other branches without full merge.
Best for: Backporting hotfixes to release branches
Git Stash — Named, Partial, and Pop Strategies
Advanced stash techniques: named stashes, partial stash, stash apply vs pop, and branch from stash.
Best for: Saving work in progress before switching branches
Git Worktree — Work on Multiple Branches
Use git worktree to check out multiple branches simultaneously in separate directories.
Best for: Reviewing PRs without stashing current work
Git Sparse Checkout — Clone Only What You Need
Use sparse checkout to clone specific directories from large monorepos without downloading everything.
Best for: Working on a specific package in a monorepo
Git Hooks — Pre-Commit Lint and Format
Set up pre-commit hooks to automatically lint, format, and validate code before every commit.
Best for: Enforcing code quality before commits
Git Blame — Ignore Formatting Commits
Configure git blame to skip formatting-only commits using .git-blame-ignore-revs for cleaner history.
Best for: Ignoring bulk formatting commits in blame output
Git Remote Prune and Branch Cleanup
Clean up stale remote-tracking branches and local branches that have been merged or deleted upstream.
Best for: Keeping local repository tidy
Git Reset — Soft, Mixed, and Hard Explained
Understand the three git reset modes and when to use each for undoing commits safely.
Best for: Undoing accidental commits before pushing
Git Amend and Fixup Commits
Amend the last commit or create fixup commits that auto-squash during rebase.
Best for: Fixing typos in the last commit message
Git Log — Search, Filter, and Visualize
Advanced git log techniques for searching commit messages, filtering by author/date, and visualizing.
Best for: Searching project history for specific changes
Git Tags — Signed Releases and Versioning
Create signed and annotated tags for releases with GPG verification and semantic versioning.
Best for: Creating verified release tags
Git Diff — Word, Stat, and Patch Options
Advanced diff techniques: word-level diff, stat summary, diff between branches, and patch creation.
Best for: Reviewing changes before committing
Git Config — Essential Global Settings
Configure Git globally with aliases, default branch, editor, credentials, and performance settings.
Best for: Setting up Git on a new machine
Git Merge Strategies — No-FF, Squash, Ours
Understand different merge strategies and when to use no-fast-forward, squash merge, and ours/theirs.
Best for: Choosing the right merge strategy for PRs
Git Submodules — Add, Update, and Pin
Manage repository dependencies with submodules: add, update, pin versions, and handle nested repos.
Best for: Sharing code libraries across multiple repos
Git Revert — Undo Merge Commits Safely
Revert merge commits safely without rewriting history, with options for parent selection.
Best for: Rolling back a broken deployment without force push
Git Bundle — Transfer Repos Offline
Create portable Git bundles for transferring repository data without network access.
Best for: Transferring repos in air-gapped environments
Git Filter-Repo — Rewrite Entire History
Use git-filter-repo to remove secrets, rename authors, or extract subdirectories from Git history.
Best for: Removing accidentally committed secrets from history
Gitflow Workflow
Git workflow: gitflow-workflow
Best for: version control
Trunk Based Development
Git workflow: trunk-based-development
Best for: version control
Feature Branch Workflow
Git workflow: feature-branch-workflow
Best for: version control
Github Flow
Git workflow: github-flow
Best for: version control
Git Hooks Pre Commit
Git workflow: git-hooks-pre-commit
Best for: version control
Git Hooks Post Commit
Git workflow: git-hooks-post-commit
Best for: version control
Husky Setup
Git workflow: husky-setup
Best for: version control
Lefthook Framework
Git workflow: lefthook-framework
Best for: version control
Git Lfs Large Files
Git workflow: git-lfs-large-files
Best for: version control
Git Annex
Git workflow: git-annex
Best for: version control
Git Sparse Checkout
Git workflow: git-sparse-checkout
Best for: version control
Git Partial Clone
Git workflow: git-partial-clone
Best for: version control
Interactive Rebase Advanced
Git workflow: interactive-rebase-advanced
Best for: version control
Rebase Merge Conflicts
Git workflow: rebase-merge-conflicts
Best for: version control
Rerere Resolution
Git workflow: rerere-resolution
Best for: version control
Git Rerere
Git workflow: git-rerere
Best for: version control
Git Subtree
Git workflow: git-subtree
Best for: version control
Git Submodule
Git workflow: git-submodule
Best for: version control
Monorepo Management
Git workflow: monorepo-management
Best for: version control
Git Blame Analysis
Git workflow: git-blame-analysis
Best for: version control
Git Log Filtering
Git workflow: git-log-filtering
Best for: version control
Git Log Graphs
Git workflow: git-log-graphs
Best for: version control
Git Statistics
Git workflow: git-statistics
Best for: version control
Git Archaeology
Git workflow: git-archaeology
Best for: version control
Code Review Process
Git workflow: code-review-process
Best for: version control
Pull Request Workflow
Git workflow: pull-request-workflow
Best for: version control
Merge Queue
Git workflow: merge-queue
Best for: version control
Auto Merge Github
Git workflow: auto-merge-github
Best for: version control
Git Signing
Git workflow: git-signing
Best for: version control
Gpg Signing
Git workflow: gpg-signing
Best for: version control
Commit Signatures
Git workflow: commit-signatures
Best for: version control
Verify Commits
Git workflow: verify-commits
Best for: version control
Git Gc Optimization
Git workflow: git-gc-optimization
Best for: version control
Git Fsck Repair
Git workflow: git-fsck-repair
Best for: version control
Git Recovery Advanced
Git workflow: git-recovery-advanced
Best for: version control
Bundle Git
Git workflow: bundle-git
Best for: version control
Git Server Setup
Git workflow: git-server-setup
Best for: version control
Gitea Self Hosted
Git workflow: gitea-self-hosted
Best for: version control
Gitolite Access
Git workflow: gitolite-access
Best for: version control
Cgit Interface
Git workflow: cgit-interface
Best for: version control
Cherry Pick Range
Git workflow: cherry-pick-range
Best for: version control
Bisect Debugging
Git workflow: bisect-debugging
Best for: version control
Worktree Multi Branch
Git workflow: worktree-multi-branch
Best for: version control
Reflog Recovery
Git workflow: reflog-recovery
Best for: version control
Stash Workflow
Git workflow: stash-workflow
Best for: version control
Commit Squash Cleanup
Git workflow: commit-squash-cleanup
Best for: version control
Filter Repo History
Git workflow: filter-repo-history
Best for: version control
Blame Ignore Revs
Git workflow: blame-ignore-revs
Best for: version control
Upstream Fork Sync
Git workflow: upstream-fork-sync
Best for: version control
Release Tagging
Git workflow: release-tagging
Best for: version control