Skip to content

jim-my/git-scripts

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

113 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Git Utility Scripts Collection

A comprehensive collection of 50+ Git utility scripts solving real workflow problems

Scripts Languages Quality

πŸš€ Quick Start

# Clone the repository
git clone https://github.com/jim-my/git-scripts.git
cd git-scripts

# Install all scripts
./install.sh

# Start using immediately
git check-dup                    # Find duplicate commits
git experiment start my-feature  # Safe experimentation
git wtf                          # Enhanced status

🌟 Featured Scripts

Script Purpose Why Use It
git-check-dup Find duplicate commits between branches Detects identical content with different hashes
git-experiment Safe code experimentation sandbox Isolated development with automatic cleanup
git-search-in-each-commit Search through commit history Fills gap in git's "contains pattern" search
git-when-reached-branch Determine when commit reached branch Comprehensive merge detection with confidence levels
git-dedupe Clean branch history automatically Remove duplicates and rebase cleanly
git-split-amended-commit Split accidentally merged commits Fixes accidental git commit --amend mistakes
git-wtf Enhanced repository status Branch relationships and sync status

πŸ“‚ Categories

πŸ” Duplicate & History Management

  • git-check-dup - Find commits with identical content between branches
  • git-dedupe - Remove duplicate commits and rebase cleanly
  • git-remove-from-history - Completely remove files/directories from history
  • git-search-in-each-commit - Search for patterns across commit history
  • git-when-reached-branch - Track when commits reached specific branches

🌿 Branch Operations

  • git-branch-current - Get current branch name safely
  • git-branch-diff - Visual diff of commit logs between branches
  • git-branch-new_and_track - Create and track new branches
  • git-branch-not-merged - List unmerged branches
  • git-branch-set_tracking - Configure branch tracking
  • git-branch-show - Show branch information
  • git-branch-tracking - Display tracking relationships
  • git-delete-local-merged - Delete local branches merged into current
  • git-promote - Promote local branch to remote tracking

πŸ”„ Workflow Helpers

  • git-amend - Amend last commit with staged changes
  • git-experiment - Safe experimentation with isolated branches
  • git-stage-all - Stage all changes with confirmation
  • git-stash-smart - Enhanced stash management with search
  • git-undo - Undo last commit but keep changes staged
  • git-up - Enhanced pull with change summary
  • git-reup - Pull with rebase and change summary

πŸ“Š Diff & Comparison Tools

  • git-diff_with_prev - Compare with previous version
  • git-resolve-conflict - Guided merge-conflict resolution with auto re-merge and review
  • git-untracked-conflict - Classify untracked files that would block a merge/pull
  • git-diff-branch - Compare branches with enhanced output
  • git-diff-changed_files - Show only changed file names
  • git-diff-theirs_combined - Show their changes in merge conflicts
  • git-diff-with-2nd-parent.rb - Compare with second parent in merges
  • git-icdiff - Side-by-side diffs with icdiff
  • git-show2 - Enhanced git show with better visualization
  • git-show-vim - Show commits in vim

πŸ“ˆ Log & Analysis

  • git-incoming - Show incoming changes from remote
  • git-log-merges - Enhanced merge commit log
  • git-log-search_all_commits - Search across all commits
  • git-ls-by-date - List files by last commit date
  • git-merged-what-log - Show what was merged
  • git-merged-what-show - Display merge details
  • git-rank-contributers - Rank contributors by diff size
  • git-show-merges - Show merge relationships
  • git-status-date - Status with date information
  • git-wtf - Comprehensive repository status

πŸ› οΈ Advanced Operations

  • git-credit - Credit authors on commits
  • git-extract-folder - Extract folder to new repository
  • git-fetch-and-checkout - Fetch and checkout in one command
  • git-find_file - Find files across all branches
  • git-merge-test - Test merge operations
  • git-move-after - Move commits to new positions
  • git-move-before - Reorder commits in history
  • git-split-amended-commit - Split accidentally merged commits

πŸ›‘οΈ Security Features

All scripts implement security best practices:

  • Input validation - All user inputs are validated and sanitized
  • Command injection protection - No unsafe string interpolation
  • Error handling - Comprehensive error checking with meaningful messages
  • Git repository validation - Verify git repository before operations
  • Safe defaults - Dry-run modes and confirmation prompts for destructive operations

πŸ“‹ Installation Methods

Method 1: Automatic Installation (Recommended)

git clone https://github.com/jim-my/git-scripts.git
cd git-scripts
./install.sh

Method 2: Manual Installation

# Clone repository
git clone https://github.com/jim-my/git-scripts.git

# Add to PATH (add to your ~/.bashrc or ~/.zshrc)
export PATH="$HOME/git-scripts:$PATH"

# Or copy to local bin directory
cp git-scripts/git-* ~/.local/bin/

Method 3: Selective Installation

# Install only specific scripts
cp git-scripts/git-check-dup ~/.local/bin/
cp git-scripts/git-experiment ~/.local/bin/
cp git-scripts/git-wtf ~/.local/bin/

πŸ’‘ Usage Examples

Duplicate Management Workflow

# Find duplicate commits between branches
git check-dup origin/main

# Remove duplicates and clean history
git dedupe --apply

Safe Experimentation

# Start experiment
git experiment start feature-xyz

# Work on changes...
git add . && git commit -m "experimental changes"

# Keep or discard
git experiment keep    # merge back to original branch
git experiment discard # delete experiment entirely

Enhanced Status & Sync

# Comprehensive repository status
git wtf

# Enhanced pull with summary
git up                 # pull with merge
git reup              # pull with rebase

Conflict Resolution with git-resolve-conflict

# 1) In an active conflict/integration flow, start guided mode
git resolve-conflict path/to/file
# -> choose edit view, save changes, and the script auto-retries merge
# -> if merge becomes clean, it applies and stages automatically

# dry-run mode: check retry outcomes without writing/staging resolved output
git resolve-conflict --dry-run path/to/file

Guided mode works for:

  • unmerged index entries (normal merge conflict files)
  • clean files during an in-progress integration flow (merge, cherry-pick, revert, rebase)

JSON mode is available for tool integrations:

# audit a historical merge commit for potential conflict-resolution risk
git resolve-conflict --commit [<merge_commit>] path/to/file --json

# find likely-conflicted merge commits (HEAD history by default)
git resolve-conflict --find -- --since='2025-01-01' --author='alice'

# optional path filter with find
git resolve-conflict --find path/to/file -- --since='2025-01-01'

--commit ... --json fields:

  • status - ok or error
  • conflict_likely - true if replaying original ours/base/theirs suggests textual conflict
  • reason - reason code for analysis outcome (for example merge_file_conflict, both_added_different_content, missing_in_*)
  • resolved, original_ours, original_theirs, original_base - temp file paths for direct diff review

--find status semantics:

  • likely_had_conflicts - at least one analyzed file looked conflict-prone
  • likely_clean - analyzed files looked clean
  • status_unknown(non_comparable_only) - no files were analyzable for that merge commit

Untracked Merge Blockers with git-untracked-conflict

# Compare untracked files in your working tree against files tracked in the target ref
git untracked-conflict origin/main

# Also show inline diffs for files that differ
git untracked-conflict origin/main --diff

# Delete only the files classified as identical (interactive confirmation)
git untracked-conflict origin/main --delete-identical

# Non-interactive deletion (e.g. scripts/CI)
git untracked-conflict origin/main --delete-identical --yes

Output buckets:

  • Identical (safe to delete) - local untracked file is byte-identical to target ref
  • Different (review before merge) - local file differs from target ref version

--delete-identical safety:

  • Interactive terminals prompt before deleting.
  • Non-interactive runs require --yes or the command exits with an error.

Checks exact path overlaps only (does not detect file/directory prefix collisions).

Historical Analysis

# Search through commit history
git search-in-each-commit --keyword "TODO" --since "2024-01-01"

# Find files in current branch trees
git find_file "config\\.yml" --local

# Find file touches in branch history
git find_file "settings\\.py" --history --local

# Find deleted file events
git find_file "legacy\\.txt" --deleted --local

# Find when commit reached main branch
git when-reached-branch abc1234 main

# List files by last modification
git ls-by-date --sort

πŸ”— Script Dependencies

Some scripts work better together:

  • git-check-dup + git-dedupe - Complete duplicate management
  • git-experiment + git-stash-smart - Enhanced experimental workflow
  • git-up/reup + git-wtf - Comprehensive sync and status workflow

πŸ§ͺ Requirements

  • Git 2.0+ (most scripts work with older versions)
  • Bash 4.0+ (for bash scripts)
  • Ruby 2.0+ (for ruby scripts)
  • Python 3.6+ (for python scripts)

Optional Dependencies

  • vim - For git-branch-diff, git-show-vim
  • icdiff - For git-show2, git-icdiff (pip install icdiff)

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-script)
  3. Follow existing patterns:
    • Add proper error handling
    • Include comprehensive documentation
    • Use security best practices
    • Add usage examples
  4. Test your script thoroughly
  5. Submit a pull request

Script Guidelines

  • Use set -euo pipefail for bash scripts
  • Validate all inputs
  • Provide --help documentation
  • Include usage examples in header
  • Follow naming convention: git-action-description

πŸ“œ License

MIT License - Feel free to use and modify

πŸ™ Acknowledgments

  • Inspired by jwiegley/git-scripts
  • git-when-reached-branch based on git-when-merged by Michael Haggerty
  • Built on top of Git's excellent foundation
  • Community contributions and feedback

πŸ“ž Support

  • Issues: Report bugs or request features via GitHub Issues
  • Discussions: Share workflows and ask questions in Discussions
  • Security: Report security issues privately via email

Scripts Index

Complete list of all 50 scripts (click to expand)

A-D

  • git-amend
  • git-branch-current
  • git-branch-diff
  • git-branch-new_and_track
  • git-branch-not-merged
  • git-branch-set_tracking
  • git-branch-show
  • git-branch-tracking
  • git-check-dup
  • git-credit
  • git-delete-local-merged
  • git-diff_with_prev
  • git-resolve-conflict
  • git-diff-branch
  • git-diff-changed_files
  • git-diff-theirs_combined
  • git-diff-with-2nd-parent.rb

E-M

  • git-experiment
  • git-extract-folder
  • git-fetch-and-checkout.rb
  • git-find_file
  • git-icdiff
  • git-incoming
  • git-log-merges.rb
  • git-log-search_all_commits
  • git-ls-by-date.sh
  • git-merge-test
  • git-merged-what-log
  • git-merged-what-show
  • git-move-after
  • git-move-before

N-Z

  • git-promote
  • git-rank-contributers
  • git-remove-from-history
  • git-dedupe
  • git-reup
  • git-search-in-each-commit
  • git-show-merges
  • git-show-vim
  • git-show2
  • git-split-amended-commit
  • git-stage-all
  • git-stash-smart
  • git-status-date
  • git-undo
  • git-untracked-conflict
  • git-up
  • git-when-reached-branch
  • git-wtf

⭐ Star this repository if you find it useful!

About

git-scripts - Git Utility Scripts Collection

Resources

Stars

Watchers

Forks

Contributors