Pane history not being saved (GitBash) #15789

Open
opened 2026-01-31 04:48:29 +00:00 by claunia · 12 comments
Owner

Originally created by @oshihirii on GitHub (Nov 6, 2021).

Originally assigned to: @DHowett on GitHub.

Windows Terminal version (or Windows build number)

Windows 10 , Version 21H1 (OS Build 19043.1288)
Windows Terminal Preview Version: 1.12.2931.0

Other Software

Git 2.33.1

Steps to reproduce

I have three Git Bash panes in my Windows Terminal Preview setup.

I close Windows Terminal Preview by clicking the X button in top right of application.

When I re-open, my most recent history is not accessible in any of these three panes (ie pressing the up and down arrows on the command line).

It seems to have saved history from before I installed Windows Terminal Preview.

I have a .bash_history file in C:\Users\Me and I can see the history entries in that file.

I don't seem to have a .bash_profile file in that location (as related answers on stack overflow have suggested looking at).

Expected Behavior

No response

Actual Behavior

See Steps to reproduce section.

Originally created by @oshihirii on GitHub (Nov 6, 2021). Originally assigned to: @DHowett on GitHub. ### Windows Terminal version (or Windows build number) Windows 10 , Version 21H1 (OS Build 19043.1288) Windows Terminal Preview Version: 1.12.2931.0 ### Other Software Git 2.33.1 ### Steps to reproduce I have three Git Bash panes in my Windows Terminal Preview setup. I close Windows Terminal Preview by clicking the `X` button in top right of application. When I re-open, my most recent history is not accessible in any of these three panes (ie pressing the up and down arrows on the command line). It seems to have saved history from before I installed Windows Terminal Preview. I have a `.bash_history` file in `C:\Users\Me` and I can see the history entries in that file. I don't seem to have a `.bash_profile` file in that location (as related answers on stack overflow have suggested looking at). ### Expected Behavior _No response_ ### Actual Behavior See `Steps to reproduce` section.
claunia added the Issue-BugProduct-TerminalArea-Server labels 2026-01-31 04:48:30 +00:00
Author
Owner

@oshihirii commented on GitHub (Nov 6, 2021):

I don't know if it is the correct thing to do, but I created a file called .bash_profile at C:\Users\Me with this content:

PROMPT_COMMAND='history -a'  

Per this answer:

https://stackoverflow.com/a/10901227

And now I can access recent command history.

@oshihirii commented on GitHub (Nov 6, 2021): I don't know if it is the correct thing to do, but I created a file called `.bash_profile` at `C:\Users\Me` with this content: PROMPT_COMMAND='history -a' Per this answer: https://stackoverflow.com/a/10901227 And now I can access recent command history.
Author
Owner

@zadjii-msft commented on GitHub (Nov 8, 2021):

Weird. That sure is interesting. I wonder if the history gets sabed when you exit bash, rather than hitting the 'X' button on the tab. I think we've seen that before somewhere actually....

Glad you got this sorted out though!

@zadjii-msft commented on GitHub (Nov 8, 2021): Weird. That sure is interesting. I wonder if the history gets sabed when you `exit` bash, rather than hitting the 'X' button on the tab. I think we've seen that before somewhere actually.... Glad you got this sorted out though!
Author
Owner

@oshihirii commented on GitHub (Nov 8, 2021):

just fyi - i tested and if i type exit it closes the pane (as you suggested - the entries are saved in .bash_history).

however that is not desired behaviour as i'd like to retain all the panes in their defined positions when i next open the app.

doing the above steps requires resetting up panes when re-opening the app.

@oshihirii commented on GitHub (Nov 8, 2021): just fyi - i tested and if i type `exit` it closes the `pane` (as you suggested - the entries are saved in `.bash_history`). however that is not desired behaviour as i'd like to retain all the panes in their defined positions when i next open the app. doing the above steps requires resetting up panes when re-opening the app.
Author
Owner

@oshihirii commented on GitHub (Apr 15, 2022):

just updating that this is still happening as at 15/04/22.

i am now running it on a new laptop and again found myself searching for "windows terminal preview not saving history".

@oshihirii commented on GitHub (Apr 15, 2022): just updating that this is still happening as at 15/04/22. i am now running it on a new laptop and again found myself searching for "windows terminal preview not saving history".
Author
Owner

@theHilikus commented on GitHub (Oct 19, 2022):

any idea why this workaround is actually needed? having to change your bash history mode to save on every command seems overkill. the problem seems to me to be that Windows Terminal is not exiting cleanly the session when you use the UI. if i do exit or ctrl+d it is persisted properly but not if i click X

Weird thing is that I have WSL2 configured and that one persists the history, but the one for git bash does not

seems to be similar to https://github.com/microsoft/vscode/issues/39877 where indeed VScode is not exiting the session cleanly

@theHilikus commented on GitHub (Oct 19, 2022): any idea why this workaround is actually needed? having to change your bash history mode to save on every command seems overkill. the problem seems to me to be that Windows Terminal is not exiting cleanly the session when you use the UI. if i do `exit` or ctrl+d it is persisted properly but not if i click X Weird thing is that I have WSL2 configured and that one persists the history, but the one for git bash does not seems to be similar to https://github.com/microsoft/vscode/issues/39877 where indeed VScode is not exiting the session cleanly
Author
Owner

@DHowett commented on GitHub (Oct 19, 2022):

I'm gonna reopen this for triage again. Thanks!

@DHowett commented on GitHub (Oct 19, 2022): I'm gonna reopen this for triage again. Thanks!
Author
Owner

@Okeanos commented on GitHub (Nov 5, 2022):

@DHowett I had a look at that the problem of Terminal not persisting Git Bash history while ago as well and wrote down my thoughts here.

TL;DR: it appears that git-bash.exe supplied by Git for Windows (MinTTY in particular only) handles signal handling differently than Windows Terminal (or VSCode for that matter) and will properly exit out of bash.exe. VSCode additionally suffers from not starting Git Bash as interactive session (which is required for automatic history handling; see microsoft/vscode#151105).

@Okeanos commented on GitHub (Nov 5, 2022): @DHowett I had a look at that the problem of Terminal not persisting Git Bash history while ago as well and wrote down my thoughts [here](https://github.com/git-for-windows/git/discussions/4071). TL;DR: it appears that `git-bash.exe` supplied by Git for Windows (`MinTTY` in particular only) handles signal handling differently than Windows Terminal (or VSCode for that matter) and will properly exit out of `bash.exe`. VSCode additionally suffers from not starting Git Bash as interactive session (which is required for automatic history handling; see microsoft/vscode#151105).
Author
Owner

@DHowett commented on GitHub (Nov 9, 2022):

Thanks for the investigation! We're looking at some other teardown issues... idly I wonder if #14282 will help. 😄

@DHowett commented on GitHub (Nov 9, 2022): Thanks for the investigation! We're looking at some other teardown issues... idly I wonder if #14282 will help. :smile:
Author
Owner

@oshihirii commented on GitHub (Jan 2, 2023):

I don't know if it is the correct thing to do, but I created a file called .bash_profile at C:\Users\Me with this content:

PROMPT_COMMAND='history -a'  

Per this answer:

https://stackoverflow.com/a/10901227

And now I can access recent command history.

Just noting, I have switched to another PC and found myself googling this issue again:

windows terminal preview not saving bash history

The environment is:

  • Windows Terminal Preview: Version: 1.16.3464.0
  • Windows 11 Home

I got it working by doing the workaround I posted above on 06/11/21.

Someone down-thumbed that post though, so maybe it's not a good thing to do 😢

@oshihirii commented on GitHub (Jan 2, 2023): > I don't know if it is the correct thing to do, but I created a file called `.bash_profile` at `C:\Users\Me` with this content: > > ``` > PROMPT_COMMAND='history -a' > ``` > > Per this answer: > > https://stackoverflow.com/a/10901227 > > And now I can access recent command history. Just noting, I have switched to another PC and found myself googling this issue again: > windows terminal preview not saving bash history The environment is: - Windows Terminal Preview: Version: 1.16.3464.0 - Windows 11 Home I got it working by doing the workaround I posted above on 06/11/21. Someone down-thumbed that post though, so maybe it's not a good thing to do :cry:
Author
Owner

@oshihirii commented on GitHub (Mar 29, 2025):

Anyone got a solution for this?

I just setup Windows Terminal Preview again on new computer, with Git Bash as Default Profile (i use three panes) and there is still no command history saved when I close and re-open WTP (I have enabled WTP setting to restore windows from previous session). When I try the fix I documented above, Windows Terminal Preview will not open afterwards (just get spinning cursor) - so that fix seems to break things now.

@oshihirii commented on GitHub (Mar 29, 2025): Anyone got a solution for this? I just setup Windows Terminal Preview again on new computer, with Git Bash as Default Profile (i use three panes) and there is still no command history saved when I close and re-open WTP (I have enabled WTP setting to restore windows from previous session). When I try the fix I documented above, Windows Terminal Preview will not open afterwards (just get spinning cursor) - so that fix seems to break things now.
Author
Owner

@SQLSlacker commented on GitHub (May 28, 2025):

I've been adding PROMPT_COMMAND='history -a' to C:\Program Files\Git\etc\bash.bashrc as my workaround.

@SQLSlacker commented on GitHub (May 28, 2025): I've been adding PROMPT_COMMAND='history -a' to C:\Program Files\Git\etc\bash.bashrc as my workaround.
Author
Owner

@davemsh commented on GitHub (Oct 14, 2025):

This is still happening. Win11 Pro, Git for Windows 2.51.0, Windows Terminal 1.23.12811.0.

@davemsh commented on GitHub (Oct 14, 2025): This is still happening. Win11 Pro, Git for Windows 2.51.0, Windows Terminal 1.23.12811.0.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#15789