From 1c92ae4183aa308a9c17fe93265d1fbbbfe9c882 Mon Sep 17 00:00:00 2001 From: John Bachir Date: Sun, 18 Jan 2026 11:00:43 -0800 Subject: [PATCH 1/8] persistent command history --- bin/git-repl | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/bin/git-repl b/bin/git-repl index a706de37..5e04a694 100755 --- a/bin/git-repl +++ b/bin/git-repl @@ -4,6 +4,9 @@ git version echo "git-extras version ""$(git-extras -v)" echo "Type 'ls' to ls files below current directory; '!command' to execute any command or just 'subcommand' to execute any git subcommand; 'quit', 'exit', 'q', ^D, or ^C to exit the git repl." +HISTFILE=~/.git_repl_history +history -r "$HISTFILE" + while true; do # Current branch cur=$(git symbolic-ref HEAD 2> /dev/null | cut -d/ -f3-) @@ -35,6 +38,7 @@ while true; do # History history -s "$cmd" + # history -a # write command to history in all cases # Built-in commands case $cmd in @@ -43,16 +47,27 @@ while true; do quit|exit|q) break;; esac + history -a # write command to history in all cases except for blank, and non-git commands + if [[ $cmd == !* ]]; then # shellcheck disable=SC2086 eval ${cmd:1} elif [[ $cmd == git* ]]; then # shellcheck disable=SC2086 + + # history -a # write command to history in all cases except for blank, non-git commands, and ! shell invocations [part 1] eval $cmd else + # history -a # write command to history in all cases except for blank, non-git commands, and ! shell invocations [part 2] eval git "$cmd" fi exit_status=$? done +# write command history in all cases, and do it all at once when shell exits. +# if process is killed, history will be lost +# other sessions can't access this history while it's running +# this is the typical behavior of bash and zsh +# history -w + echo From 4a61ed012687a97874d167b61a7e0583b789ab67 Mon Sep 17 00:00:00 2001 From: John Bachir Date: Sun, 18 Jan 2026 11:02:12 -0800 Subject: [PATCH 2/8] notes --- bin/git-repl | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/bin/git-repl b/bin/git-repl index 5e04a694..18a1847e 100755 --- a/bin/git-repl +++ b/bin/git-repl @@ -4,7 +4,10 @@ git version echo "git-extras version ""$(git-extras -v)" echo "Type 'ls' to ls files below current directory; '!command' to execute any command or just 'subcommand' to execute any git subcommand; 'quit', 'exit', 'q', ^D, or ^C to exit the git repl." -HISTFILE=~/.git_repl_history +# global history for all projects. we could make option for per-project history +# for my use, i want this global history, and it's also much more simple to implement +# name is analogous to bash_history and zsh_history +HISTFILE=~/.git_repl_history history -r "$HISTFILE" while true; do From 5ec41a6582abfbc02f7c74463bba207748bf4858 Mon Sep 17 00:00:00 2001 From: John Bachir Date: Sun, 18 Jan 2026 19:44:15 -0800 Subject: [PATCH 3/8] decision on which commands to save --- bin/git-repl | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/bin/git-repl b/bin/git-repl index 18a1847e..bdf3860a 100755 --- a/bin/git-repl +++ b/bin/git-repl @@ -41,7 +41,6 @@ while true; do # History history -s "$cmd" - # history -a # write command to history in all cases # Built-in commands case $cmd in @@ -50,27 +49,18 @@ while true; do quit|exit|q) break;; esac - history -a # write command to history in all cases except for blank, and non-git commands + history -a if [[ $cmd == !* ]]; then # shellcheck disable=SC2086 eval ${cmd:1} elif [[ $cmd == git* ]]; then # shellcheck disable=SC2086 - - # history -a # write command to history in all cases except for blank, non-git commands, and ! shell invocations [part 1] eval $cmd else - # history -a # write command to history in all cases except for blank, non-git commands, and ! shell invocations [part 2] eval git "$cmd" fi exit_status=$? done -# write command history in all cases, and do it all at once when shell exits. -# if process is killed, history will be lost -# other sessions can't access this history while it's running -# this is the typical behavior of bash and zsh -# history -w - echo From cbc2d2127b27c2c71ea0b0017f726a6a9bacee06 Mon Sep 17 00:00:00 2001 From: John Bachir Date: Sun, 18 Jan 2026 19:50:52 -0800 Subject: [PATCH 4/8] configurable history location --- bin/git-repl | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/bin/git-repl b/bin/git-repl index bdf3860a..286a20fc 100755 --- a/bin/git-repl +++ b/bin/git-repl @@ -4,10 +4,12 @@ git version echo "git-extras version ""$(git-extras -v)" echo "Type 'ls' to ls files below current directory; '!command' to execute any command or just 'subcommand' to execute any git subcommand; 'quit', 'exit', 'q', ^D, or ^C to exit the git repl." -# global history for all projects. we could make option for per-project history -# for my use, i want this global history, and it's also much more simple to implement -# name is analogous to bash_history and zsh_history -HISTFILE=~/.git_repl_history +use_local_history=$(git config --get --default 'false' git-extras.repl.use-local-history) +if [[ "$use_local_history" == "true" ]]; then + HISTFILE="$(git rev-parse --show-toplevel)/.git_repl_history" +else + HISTFILE=~/.git_repl_history +fi history -r "$HISTFILE" while true; do From 98b004adb85a2a227445d275b1546614e62e7eb7 Mon Sep 17 00:00:00 2001 From: John Bachir Date: Sun, 18 Jan 2026 21:06:24 -0800 Subject: [PATCH 5/8] fix history initialization in various scenarios --- bin/git-repl | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/bin/git-repl b/bin/git-repl index 286a20fc..03073629 100755 --- a/bin/git-repl +++ b/bin/git-repl @@ -10,7 +10,12 @@ if [[ "$use_local_history" == "true" ]]; then else HISTFILE=~/.git_repl_history fi -history -r "$HISTFILE" + +# file doesn't exist, is empty, or contains only whitespace +if [[ ! -f "$HISTFILE" ]] || [[ ! -s "$HISTFILE" ]] || ! grep -q '[^[:space:]]' "$HISTFILE"; then + echo '!echo welcome to git-repl!' >> "$HISTFILE" +fi +history -r while true; do # Current branch From 4855890085430a627fa2e032753a3a55836e6ac8 Mon Sep 17 00:00:00 2001 From: John Bachir Date: Sun, 18 Jan 2026 21:12:49 -0800 Subject: [PATCH 6/8] documentation --- Commands.md | 13 +++++++++++++ man/git-repl.1 | 14 +++++++++++--- man/git-repl.html | 19 ++++++++++++++++--- man/git-repl.md | 12 ++++++++++++ 4 files changed, 52 insertions(+), 6 deletions(-) diff --git a/Commands.md b/Commands.md index fa596142..5600559e 100644 --- a/Commands.md +++ b/Commands.md @@ -392,6 +392,19 @@ Type `exit`, `quit`, or `q` to end the repl session. Any arguments to git repl will be taken as the first command to execute in the repl. +### CONFIGURATION + +Commands entered in a repl session will be saved to a history file and be available in +future sessions, similar to a shell or programming language repl. By default, +there is one global history file, ~/.git_repl_history. You can specify that your projects +each have their own independent history file. This file will be saved in .git_repl_history +at the top level of the repo, and will need to be added to the repo or global .gitignore. + +```bash +# remove the --global flag to configure only an individual project to have its own history file +git config --global git-extras.repl.use-local-history "true" +``` + ```bash $ git repl git version 2.34.1 diff --git a/man/git-repl.1 b/man/git-repl.1 index b3721f44..d77513ae 100644 --- a/man/git-repl.1 +++ b/man/git-repl.1 @@ -1,6 +1,6 @@ -.\" generated with Ronn-NG/v0.9.1 -.\" http://github.com/apjanke/ronn-ng/tree/0.9.1 -.TH "GIT\-REPL" "1" "September 2024" "" "Git Extras" +.\" generated with Ronn-NG/v0.10.1 +.\" http://github.com/apjanke/ronn-ng/tree/0.10.1 +.TH "GIT\-REPL" "1" "January 2026" "" "Git Extras" .SH "NAME" \fBgit\-repl\fR \- git read\-eval\-print\-loop .SH "SYNOPSIS" @@ -31,6 +31,14 @@ Equivalent of 'git ls\-files'\. exit|quit|q .P Ends the repl session\. +.SH "CONFIGURATION" +Commands entered in a repl session will be saved to a history file and be available in future sessions, similar to a shell or programming language repl\. By default, there is one global history file, ~/\.git_repl_history\. You can specify that your projects each have their own independent history file\. This file will be saved in \.git_repl_history at the top level of the repo, and will need to be added to the repo or global \.gitignore\. +.IP "" 4 +.nf + # remove the \-\-global flag to configure only an individual project to have its own history file + git config \-\-global git\-extras\.repl\.use\-local\-history "true" +.fi +.IP "" 0 .SH "EXAMPLES" .nf $ git repl diff --git a/man/git-repl.html b/man/git-repl.html index 3f9750e6..99e88168 100644 --- a/man/git-repl.html +++ b/man/git-repl.html @@ -1,8 +1,8 @@ - - + + git-repl(1) - git read-eval-print-loop