I am using Git for Windows (ver. 1.7.8-preview20111206) and even though I have a .bash_history file in my HOME folder, it never automatically gets updated. When I start Git Bash, I can see in the history commands that I manually added to the .bash_history file, but it does not get updated automatically.
I used the shopt -s histappend
command to make sure that the history gets saved every time I close the shell, but it does not work.
If I manually use the history -w
command, then my file gets updated, but I would want to understand why the shopt command does not work as I understand it should.
Anyone can tell me why is this behavior happening?
Please note: Using Git from Command Prompt (cmd.exe, Git CMD) is deprecated as of this Git for Windows version. The default is to have git. exein the PATH, so there is no noticeable difference between cmd.exe and using the Git CMD start menu shortcut.
bash_history? You only have to do it once though. The next time you close the window it will save. Or CTRL-D for fast exit also working.
Git Bash comes included as part of the Git For Windows package. Download and install Git For Windows like other Windows applications. Once downloaded find the included .exe file and open to execute Git Bash.
As it was said here, to save git bash history on Windows you must not close the terminal with X button. Use exit command instead. History of commands will be saved then regardless of configuration mentioned in the accepted answer. Show activity on this post. To do this from the console (git bash) itself use the following commands
Note that it is technically different from Bash. On my same machine when I run: To update to the latest version of Git and Git Bash, you can download and install the latest version of Git for Windows. As per this FAQ, settings/customizations should be preserved if they were installed in the appropriate configuration folders.
The command shown is ls (history from git bash instead of git bash from vs code session). Or history of the commands to be remembered per project/path. All the history is managed by the shell, in this case git bash. If you launch a single shell and exit it, the history will likely be retained.
Put simply, Git Bash is an application for Microsoft Windows OS environments that provides Unix based shell utilities and experience for Git command line commands. Git Bash emulates the Git command line experience that Unix environments have, for Windows users. Most Windows users download Git Bash when they first install Git for Windows.
I put this in my ~/.bash_profile
PROMPT_COMMAND='history -a'
As it was said here, to save git bash history on Windows you must not close the terminal with X button. Use exit
command instead. History of commands will be saved then regardless of configuration mentioned in the accepted answer.
Create the following files
~/.bash_profile
~/.bashrc
And put the following line in both of them
PROMPT_COMMAND='history -a'
To do this from the console (Git Bash) itself, use the following commands:
echo "PROMPT_COMMAND='history -a'" >> ~/.bash_profile
echo "PROMPT_COMMAND='history -a'" >> ~/.bashrc
history -a
meansFrom the history --help
command
-a
append history lines from this session to the history file
PROMPT_COMMAND
?Bash provides an environment variable called
PROMPT_COMMAND
. The contents of this variable are executed as a regular Bash command just before Bash displays a prompt.
.bash_profile
and .bashrc
.bash_profile
is executed for login shells, while .bashrc
is executed for interactive non-login shells.
When you login (type username and password) via console, either sitting at the machine, or remotely via ssh
: .bash_profile
is executed to configure your shell before the initial command prompt.
But, if you’ve already logged into your machine and open a new terminal window (xterm) then .bashrc
is executed before the window command prompt. .bashrc
is also run when you start a new bash instance by typing /bin/bash
in a terminal.
On OS X, Terminal by default runs a login shell every time, so this is a little different to most other systems, but you can configure that in the preferences.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With