#git

100 snippets tagged with #git

bashbeginner

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#undo
bashintermediate

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#rebase
bashintermediate

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

#git#cherry-pick
bashintermediate

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#squash
bashbeginner

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

#git#stash
bashbeginner

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

#git#branch
bashbeginner

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

#git#branch
bashintermediate

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#merge
bashadvanced

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#rebase
bashbeginner

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#revert
bashbeginner

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#reset
bashintermediate

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#force-push
bashbeginner

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#clone
bashbeginner

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#shallow-clone
bashintermediate

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#hooks
bashadvanced

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#bisect
bashadvanced

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#worktree
bashadvanced

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#submodules
bashbeginner

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#log
bashbeginner

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#tags
bashintermediate

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#reflog
bashbeginner

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

#git#aliases
bashbeginner

.gitignore Patterns and Templates

Comprehensive .gitignore patterns for Node.js, Python, and general development environments.

Best for: Setting up gitignore for new projects

#git#gitignore
bashintermediate

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#patch
bashintermediate

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#blame
bashadvanced

Git Rebase Strategies Guide

Advanced rebase strategies for cleaning history including onto, autosquash, and conflict resolution.

Best for: Cleaning commit history before merging

#git#rebase
bashintermediate

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#diff
bashbeginner

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#archive
bashadvanced

Git Subtree Workflow

Use git subtree to include external repositories as subdirectories without submodule complexity.

Best for: Including shared code without submodule complexity

#git#subtree
bashintermediate

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

#git#cleanup
bashintermediate

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#rebase
bashintermediate

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#bisect
bashintermediate

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#cherry-pick
bashbeginner

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#stash
bashadvanced

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#worktree
bashadvanced

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#sparse-checkout
bashintermediate

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#hooks
bashintermediate

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#blame
bashbeginner

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#cleanup
bashbeginner

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#reset
bashbeginner

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#amend
bashintermediate

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#log
bashintermediate

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#tags
bashbeginner

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#diff
bashbeginner

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#config
bashintermediate

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#merge
bashadvanced

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#submodule
bashadvanced

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#revert
bashadvanced

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#bundle
bashadvanced

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

#git#filter-repo
bashbeginner

Gitflow Workflow

Git workflow: gitflow-workflow

Best for: version control

#git#version-control
bashintermediate

Trunk Based Development

Git workflow: trunk-based-development

Best for: version control

#git#version-control
bashadvanced

Feature Branch Workflow

Git workflow: feature-branch-workflow

Best for: version control

#git#version-control
bashbeginner

Github Flow

Git workflow: github-flow

Best for: version control

#git#version-control
bashintermediate

Git Hooks Pre Commit

Git workflow: git-hooks-pre-commit

Best for: version control

#git#version-control
bashadvanced

Git Hooks Post Commit

Git workflow: git-hooks-post-commit

Best for: version control

#git#version-control
bashbeginner

Husky Setup

Git workflow: husky-setup

Best for: version control

#git#version-control
bashintermediate

Lefthook Framework

Git workflow: lefthook-framework

Best for: version control

#git#version-control
bashadvanced

Git Lfs Large Files

Git workflow: git-lfs-large-files

Best for: version control

#git#version-control
bashbeginner

Git Annex

Git workflow: git-annex

Best for: version control

#git#version-control
bashintermediate

Git Sparse Checkout

Git workflow: git-sparse-checkout

Best for: version control

#git#version-control
bashadvanced

Git Partial Clone

Git workflow: git-partial-clone

Best for: version control

#git#version-control
bashbeginner

Interactive Rebase Advanced

Git workflow: interactive-rebase-advanced

Best for: version control

#git#version-control
bashintermediate

Rebase Merge Conflicts

Git workflow: rebase-merge-conflicts

Best for: version control

#git#version-control
bashadvanced

Rerere Resolution

Git workflow: rerere-resolution

Best for: version control

#git#version-control
bashbeginner

Git Rerere

Git workflow: git-rerere

Best for: version control

#git#version-control
bashintermediate

Git Subtree

Git workflow: git-subtree

Best for: version control

#git#version-control
bashadvanced

Git Submodule

Git workflow: git-submodule

Best for: version control

#git#version-control
bashbeginner

Monorepo Management

Git workflow: monorepo-management

Best for: version control

#git#version-control
bashintermediate

Git Blame Analysis

Git workflow: git-blame-analysis

Best for: version control

#git#version-control
bashadvanced

Git Log Filtering

Git workflow: git-log-filtering

Best for: version control

#git#version-control
bashbeginner

Git Log Graphs

Git workflow: git-log-graphs

Best for: version control

#git#version-control
bashintermediate

Git Statistics

Git workflow: git-statistics

Best for: version control

#git#version-control
bashadvanced

Git Archaeology

Git workflow: git-archaeology

Best for: version control

#git#version-control
bashbeginner

Code Review Process

Git workflow: code-review-process

Best for: version control

#git#version-control
bashintermediate

Pull Request Workflow

Git workflow: pull-request-workflow

Best for: version control

#git#version-control
bashadvanced

Merge Queue

Git workflow: merge-queue

Best for: version control

#git#version-control
bashbeginner

Auto Merge Github

Git workflow: auto-merge-github

Best for: version control

#git#version-control
bashintermediate

Git Signing

Git workflow: git-signing

Best for: version control

#git#version-control
bashadvanced

Gpg Signing

Git workflow: gpg-signing

Best for: version control

#git#version-control
bashbeginner

Commit Signatures

Git workflow: commit-signatures

Best for: version control

#git#version-control
bashintermediate

Verify Commits

Git workflow: verify-commits

Best for: version control

#git#version-control
bashadvanced

Git Gc Optimization

Git workflow: git-gc-optimization

Best for: version control

#git#version-control
bashbeginner

Git Fsck Repair

Git workflow: git-fsck-repair

Best for: version control

#git#version-control
bashintermediate

Git Recovery Advanced

Git workflow: git-recovery-advanced

Best for: version control

#git#version-control
bashadvanced

Bundle Git

Git workflow: bundle-git

Best for: version control

#git#version-control
bashbeginner

Git Server Setup

Git workflow: git-server-setup

Best for: version control

#git#version-control
bashintermediate

Gitea Self Hosted

Git workflow: gitea-self-hosted

Best for: version control

#git#version-control
bashadvanced

Gitolite Access

Git workflow: gitolite-access

Best for: version control

#git#version-control
bashbeginner

Cgit Interface

Git workflow: cgit-interface

Best for: version control

#git#version-control
bashintermediate

Cherry Pick Range

Git workflow: cherry-pick-range

Best for: version control

#git#version-control
bashadvanced

Bisect Debugging

Git workflow: bisect-debugging

Best for: version control

#git#version-control
bashbeginner

Worktree Multi Branch

Git workflow: worktree-multi-branch

Best for: version control

#git#version-control
bashintermediate

Reflog Recovery

Git workflow: reflog-recovery

Best for: version control

#git#version-control
bashadvanced

Stash Workflow

Git workflow: stash-workflow

Best for: version control

#git#version-control
bashbeginner

Commit Squash Cleanup

Git workflow: commit-squash-cleanup

Best for: version control

#git#version-control
bashintermediate

Filter Repo History

Git workflow: filter-repo-history

Best for: version control

#git#version-control
bashadvanced

Blame Ignore Revs

Git workflow: blame-ignore-revs

Best for: version control

#git#version-control
bashbeginner

Upstream Fork Sync

Git workflow: upstream-fork-sync

Best for: version control

#git#version-control
bashintermediate

Release Tagging

Git workflow: release-tagging

Best for: version control

#git#version-control