A Go port of Git's interactive add functionality, providing the same interface as git add -i and git add -p, with a few enhancements.

y/n/s/e/q/a/d commandsThis Go implementation adds several powerful features beyond the original Perl script:
Filter hunks across all files using regex patterns:
G <regex> # Set global filter to show only hunks matching pattern
G # Clear filter (interactive prompt for new pattern)
Example workflows:
G TODO - Show only hunks containing "TODO" commentsG import - Focus on import statement changesG console\.log - Find all debugging statementsAutomatically split all hunks to maximum granularity:
S # Enable auto-splitting globally and split all hunks
This recursively splits hunks until no further splitting is possible, giving you the finest possible control over what gets staged.
Accept all hunks across all files (after filtering and splitting):
A # Accept all visible hunks in all remaining files
Powerful workflow combinations:
S → G <pattern> → A - Split everything, filter by pattern, accept all matchesG console\.log → A - Quickly stage all debugging code across your entire changeset/): Search within current file without affecting global filter[filter: pattern] and [auto-split] indicatorsgo build .
To use this implementation as the default git add -i and git add -p, you can install it to your Go bin directory and update your Git exec path:
# Build and install to Go bin directory
go build -o "$(go env GOPATH)/bin/git-add--interactive" .
# Add Go bin to Git's exec path (add to your shell profile for persistence)
export GIT_EXEC_PATH="$(go env GOPATH)/bin:$(git --exec-path)"
After setting this up, git add -i and git add -p will use the Go implementation instead of the Perl script.
# Check which git-add--interactive is being used
which git-add--interactive
# Test interactive add
git add -i
# Test patch mode
git add -p
To revert back to the original Perl implementation:
# Remove the Go binary from your Go bin
rm "$(go env GOPATH)/bin/git-add--interactive"
# Reset Git exec path (remove from your shell profile too)
unset GIT_EXEC_PATH
# Or set it back to default
export GIT_EXEC_PATH="$(git --exec-path)"
# Run directly
./git-add--interactive
# Or if installed as Git command
git add -i
This launches the main interactive menu with options:
status - Show paths with changesupdate - Add working tree state to staged changesrevert - Revert staged changes back to HEADadd untracked - Add untracked files to staged changespatch - Pick hunks and update selectivelydiff - View diff between HEAD and indexquit - Exit the programhelp - Show help# Direct usage
./git-add--interactive --patch --
./git-add--interactive --patch=stage --
./git-add--interactive --patch=reset --
./git-add--interactive --patch=checkout --
# Or if installed as Git command
git add -p # Same as --patch
git add --patch # Stage mode
git reset -p # Reset mode
git checkout -p # Checkout mode
Patch mode allows you to interactively select hunks with these commands:
y - Accept this hunkn - Skip this hunkq - Quit; skip this hunk and remaining onesa - Accept this hunk and all later hunks in the filed - Skip this hunk and all later hunks in the files - Split the current hunk into smaller hunkse - Manually edit the current hunkj/k - Navigate to next/previous undecided hunkJ/K - Navigate to next/previous hunkg - Go to a specific hunk number/ - Search for pattern in current fileG - Set global filter for all files (or clear with empty pattern)S - Enable auto-splitting globally and split all hunksA - Accept all hunks in all remaining files? - Show helpThe codebase is organized into these main packages:
main.go - Entry point and command-line parsinginternal/git/ - Git repository interaction and operations
repository.go - Git repository abstraction and command executionstatus.go - File status parsing and trackingpatch.go - Diff parsing and patch mode operationsinternal/ui/ - Interactive terminal interface
app.go - Main application logic and menu systempatch.go - Patch mode UI and hunk interactionRun the test suite:
go test ./...
Run tests with verbose output:
go test -v ./...
The code follows Go conventions and includes:
This implementation provides the same functionality as the original Perl git-add--interactive script, including:
19 commits
Go
100.0%
A Go port of Git's interactive add functionality, providing the same interface as git add -i and git add -p, with a few enhancements.

y/n/s/e/q/a/d commandsThis Go implementation adds several powerful features beyond the original Perl script:
Filter hunks across all files using regex patterns:
G <regex> # Set global filter to show only hunks matching pattern
G # Clear filter (interactive prompt for new pattern)
Example workflows:
G TODO - Show only hunks containing "TODO" commentsG import - Focus on import statement changesG console\.log - Find all debugging statementsAutomatically split all hunks to maximum granularity:
S # Enable auto-splitting globally and split all hunks
This recursively splits hunks until no further splitting is possible, giving you the finest possible control over what gets staged.
Accept all hunks across all files (after filtering and splitting):
A # Accept all visible hunks in all remaining files
Powerful workflow combinations:
S → G <pattern> → A - Split everything, filter by pattern, accept all matchesG console\.log → A - Quickly stage all debugging code across your entire changeset/): Search within current file without affecting global filter[filter: pattern] and [auto-split] indicatorsgo build .
To use this implementation as the default git add -i and git add -p, you can install it to your Go bin directory and update your Git exec path:
# Build and install to Go bin directory
go build -o "$(go env GOPATH)/bin/git-add--interactive" .
# Add Go bin to Git's exec path (add to your shell profile for persistence)
export GIT_EXEC_PATH="$(go env GOPATH)/bin:$(git --exec-path)"
After setting this up, git add -i and git add -p will use the Go implementation instead of the Perl script.
# Check which git-add--interactive is being used
which git-add--interactive
# Test interactive add
git add -i
# Test patch mode
git add -p
To revert back to the original Perl implementation:
# Remove the Go binary from your Go bin
rm "$(go env GOPATH)/bin/git-add--interactive"
# Reset Git exec path (remove from your shell profile too)
unset GIT_EXEC_PATH
# Or set it back to default
export GIT_EXEC_PATH="$(git --exec-path)"
# Run directly
./git-add--interactive
# Or if installed as Git command
git add -i
This launches the main interactive menu with options:
status - Show paths with changesupdate - Add working tree state to staged changesrevert - Revert staged changes back to HEADadd untracked - Add untracked files to staged changespatch - Pick hunks and update selectivelydiff - View diff between HEAD and indexquit - Exit the programhelp - Show help# Direct usage
./git-add--interactive --patch --
./git-add--interactive --patch=stage --
./git-add--interactive --patch=reset --
./git-add--interactive --patch=checkout --
# Or if installed as Git command
git add -p # Same as --patch
git add --patch # Stage mode
git reset -p # Reset mode
git checkout -p # Checkout mode
Patch mode allows you to interactively select hunks with these commands:
y - Accept this hunkn - Skip this hunkq - Quit; skip this hunk and remaining onesa - Accept this hunk and all later hunks in the filed - Skip this hunk and all later hunks in the files - Split the current hunk into smaller hunkse - Manually edit the current hunkj/k - Navigate to next/previous undecided hunkJ/K - Navigate to next/previous hunkg - Go to a specific hunk number/ - Search for pattern in current fileG - Set global filter for all files (or clear with empty pattern)S - Enable auto-splitting globally and split all hunksA - Accept all hunks in all remaining files? - Show helpThe codebase is organized into these main packages:
main.go - Entry point and command-line parsinginternal/git/ - Git repository interaction and operations
repository.go - Git repository abstraction and command executionstatus.go - File status parsing and trackingpatch.go - Diff parsing and patch mode operationsinternal/ui/ - Interactive terminal interface
app.go - Main application logic and menu systempatch.go - Patch mode UI and hunk interactionRun the test suite:
go test ./...
Run tests with verbose output:
go test -v ./...
The code follows Go conventions and includes:
This implementation provides the same functionality as the original Perl git-add--interactive script, including:
19 commits
Go
100.0%