Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions Commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 21 additions & 2 deletions bin/git-repl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,21 @@ 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."

HISTCONTROL=ignoredups
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

# file doesn't exist, is empty, or contains only whitespace
if [[ ! -f "$HISTFILE" ]] || [[ ! -s "$HISTFILE" ]] || ! grep -q '[^[:space:]]' "$HISTFILE"; then
# `history -r` .... `history -a` are not happy with an empty initial file
echo '!echo welcome to git-repl!' >> "$HISTFILE"
fi
history -r

while true; do
# Current branch
cur=$(git symbolic-ref HEAD 2> /dev/null | cut -d/ -f3-)
Expand Down Expand Up @@ -33,8 +48,10 @@ while true; do
test $? -ne 0 && break
fi

# History
history -s "$cmd"
# Add command to history if it is not all whitespace
if [[ ! "$cmd" =~ ^[[:space:]]*$ ]]; then
history -s "$cmd"
fi

# Built-in commands
case $cmd in
Expand All @@ -43,6 +60,8 @@ while true; do
quit|exit|q) break;;
esac

history -a

if [[ $cmd == !* ]]; then
# shellcheck disable=SC2086
eval ${cmd:1}
Expand Down
14 changes: 11 additions & 3 deletions man/git-repl.1
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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
Expand Down
19 changes: 16 additions & 3 deletions man/git-repl.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions man/git-repl.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,18 @@ git-repl(1) -- git read-eval-print-loop

Ends the repl session.

## 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"
```

## EXAMPLES

Expand Down