git-scripts¶
Git scripts written by different people.
Installation¶
Note: some scripts depend on each other, so it's a good idea to put this folder in your
$PATH.
✈️ DANGER ZONE ✈️ Destructive Commands¶
Don't run these commands willy nilly unless you like working on the weekend
These scripts can permanently destroy your work, rewrite history, or discard uncommitted changes. Some scripts should have warnings and require --force flags, but this is a fork, so who knows on some of them. Always read the script first and understand what it does before running it.
🔴 Extremely Dangerous (History Rewriting)¶
git-remove-empty-commits- Usesgit filter-branchto rewrite history. Can break shared repositories and cause data loss, especially with outdated reflogs.
⚠️ Destructive (Discards Changes)¶
These scripts use git reset --hard, git clean -f, or similar operations that permanently discard uncommitted changes:
git-undo- Usesgit reset --hardto undo operations (discards all uncommitted changes)git-full-reset-git reset --hard HEAD && git clean -fdx(nuclear option - discards everything)git-smerge- Usesgit reset --hardduring merge operationsgit-trash- Usesgit reset --hardto discard changesgit-build- Usesgit cleanandgit reset --hardto clean build artifactsgit-empty-branch- Usesgit clean -f -dto remove untracked files
Before running any of these: Make sure you have a server backup and a backup of your local files. While committing and stashing your work is important too, many of these commands will rewrite your local and server history, clear your stashes, and even impact your reflogs. You should understand what the command will do. These operations can be irreversible.
General Patterns for investigating deleted/rebased/diverged commits¶
git reflog - It shows what branches USED to point to, along with commit history and force-pushes:
git-find-useful-dangling-trees - A forensics tool for detecting hidden deleted/rebased/diverged commits:
git-find-useful-dangling-trees 10 100
# Finds commits that exist but aren't reachable - the "deleted" history (also false positives from squashes and rebase merges)
git fsck - A tool for checking the integrity of the repository:
git fsck
# Finds commits that exist but aren't reachable - the "deleted" history (also false positives from squashes and rebase merges)
git fsck --lost-found
# Finds commits that exist but aren't reachable - copies a record in the .git/lost-found/ folder
Check for divergent SHAs:
Pattern: Identical commits with different SHAs:
git log --pretty="%H %s" | sort -k2 | uniq -D -f1
# Finds commits with same message but different SHAs (rebase victims)
Essential Scripts¶
These are the standout scripts that are particularly useful, interesting, or solve common Git workflow problems:
Repository Analysis & Visualization¶
git-wtf - Comprehensive repository status display
- Shows branch relationships, tracking status, and merge information
- Essential for understanding complex repository state before push/pull
git-wtf # Current branch status
git-wtf --relations # Show feature/integration branch relationships
git-wtf --long # Include author info and dates
git-forest - Beautiful ASCII tree visualization of Git history
- Creates text-based commit trees with branches and merges
- Perfect for understanding complex history
git-find-useful-dangling-trees - Repository forensics tool
- Finds lost commits and dangling objects with closest matches
- Essential for recovering from force-pushes or accidental deletions
git-find-useful-dangling-trees
git-find-useful-dangling-trees 10 50 7 # 10 commits, 50 objects, 7 days
Branch Management & Workflow¶
git-branch-status - Multi-repository branch status
- Shows status across multiple repositories at once
- Perfect for managing multiple projects
git-smart-merge - Intelligent merge with fallback strategies
- Tries simple merge first, then rebase-merge if that fails
- Handles difficult merges automatically
git-branch-done - Complete feature branch workflow
- Merges feature branch with no-fast-forward and cleans up
- Perfect for finishing feature branches properly
Repository Maintenance & Cleanup¶
git-flush - Aggressive repository compaction
- Removes reflogs, stashes, and cruft for maximum compression
- Essential before sharing repositories
git-maxpack - Maximum compression optimization
- Configures optimal pack settings and repacks for smallest size
- Perfect for minimizing repository size
git-stale-branches - Find merged branches for cleanup
- Identifies branches that have been merged and can be deleted
- Essential for repository housekeeping
Multi-Repository Operations¶
git-each - Execute commands across multiple repositories
- Runs Git commands on all repositories in parallel using GNU parallel
- Perfect for bulk operations across projects
git-sync - Synchronize all repositories
- Fetches updates for all repositories, supports git-svn and gc-utils
- Essential for maintaining multiple repositories
Development Workflow¶
git-standup - Daily standup reports
- Shows commits since yesterday (or last Friday if Monday)
- Perfect for daily status reports
git-pr - GitHub pull request management
- Fetches and checks out pull requests locally
- Essential for reviewing and testing PRs
git-record - Interactive darcs-style staging
- Emulates darcs record interface for granular commit control
- Perfect for selective staging and commits
Advanced & Specialized¶
git-undo - Comprehensive undo operations
- Undoes various Git operations based on type (commit, add, merge, etc.)
- Essential for fixing mistakes
git-svn-diff - SVN-compatible diffs
- Creates SVN-format diffs from Git-SVN repositories
- Essential for Git-SVN workflows
git-discover-large-blobs - Find repository bloat
- Identifies the largest objects making your repository large
- Essential for repository size optimization