Skip to content

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.

## or git-bash
PATH=$PATH:/c/work/Github/git-scripts
ls /c/work/Github/git-scripts
$env:PATH += ";C:\work\Github\git-scripts"
gci C:\work\Github\git-scripts

✈️ 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 - Uses git filter-branch to 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 - Uses git reset --hard to undo operations (discards all uncommitted changes)
  • git-full-reset - git reset --hard HEAD && git clean -fdx (nuclear option - discards everything)
  • git-smerge - Uses git reset --hard during merge operations
  • git-trash - Uses git reset --hard to discard changes
  • git-build - Uses git clean and git reset --hard to clean build artifacts
  • git-empty-branch - Uses git clean -f -d to 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 reflog show main
# Look for force-push patterns: HEAD@{X} moving backward in history

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:

git log --oneline --graph --all --reflog
# The --reflog flag shows "deleted" commits

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-forest                 # Show current branch tree
git-forest --all           # Show all branches

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-branch-status
git-branch-status --all

git-smart-merge - Intelligent merge with fallback strategies

  • Tries simple merge first, then rebase-merge if that fails
  • Handles difficult merges automatically
git-smart-merge feature-branch

git-branch-done - Complete feature branch workflow

  • Merges feature branch with no-fast-forward and cleans up
  • Perfect for finishing feature branches properly
git-branch-done main

Repository Maintenance & Cleanup

git-flush - Aggressive repository compaction

  • Removes reflogs, stashes, and cruft for maximum compression
  • Essential before sharing repositories
git-flush                  # Clean up repository
git-flush -f              # Also clear stash

git-maxpack - Maximum compression optimization

  • Configures optimal pack settings and repacks for smallest size
  • Perfect for minimizing repository size
git-maxpack

git-stale-branches - Find merged branches for cleanup

  • Identifies branches that have been merged and can be deleted
  • Essential for repository housekeeping
git-stale-branches

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-each git status        # Status of all repos
git-each git pull          # Pull all repositories

git-sync - Synchronize all repositories

  • Fetches updates for all repositories, supports git-svn and gc-utils
  • Essential for maintaining multiple repositories
git-sync                   # Sync current directory
git-sync /path/to/repos    # Sync specific directories

Development Workflow

git-standup - Daily standup reports

  • Shows commits since yesterday (or last Friday if Monday)
  • Perfect for daily status reports
git-standup                # Your commits since yesterday
git-standup "John Doe"     # Someone else's commits

git-pr - GitHub pull request management

  • Fetches and checks out pull requests locally
  • Essential for reviewing and testing PRs
git-pr 123                 # Check out PR #123
git-pr clean              # Clean up old PR branches

git-record - Interactive darcs-style staging

  • Emulates darcs record interface for granular commit control
  • Perfect for selective staging and commits
git-record                 # Interactive staging

Advanced & Specialized

git-undo - Comprehensive undo operations

  • Undoes various Git operations based on type (commit, add, merge, etc.)
  • Essential for fixing mistakes
git-undo commit            # Undo last commit
git-undo add file.txt      # Unstage file
git-undo merge             # Undo merge

git-svn-diff - SVN-compatible diffs

  • Creates SVN-format diffs from Git-SVN repositories
  • Essential for Git-SVN workflows
git-svn-diff               # SVN-compatible diff

git-discover-large-blobs - Find repository bloat

  • Identifies the largest objects making your repository large
  • Essential for repository size optimization
git-discover-large-blobs