Git for Windows doesn't execute my .bashrc file

Jez picture Jez · Aug 24, 2015 · Viewed 19.5k times · Source

I've just installed Git for Windows 2.5.0 on Windows 7, and it appears that my .bashrc file is not being executed when I run Git Bash.

I created the file like so:

Administrator@HintTech-Dev MINGW64 /
$ pwd
/

Administrator@HintTech-Dev MINGW64 /
$ cd ~

Administrator@HintTech-Dev MINGW64 ~
$ pwd
/c/Users/Administrator

Administrator@HintTech-Dev MINGW64 ~
$ touch .bashrc

Administrator@HintTech-Dev MINGW64 ~
$ vi .bashrc

[... I insert the line "ZZZTESTVAR=234" (without the quotes) into the file in vim ...]

Administrator@HintTech-Dev MINGW64 ~
$ exit

Yet, when I next run Git Bash:

Administrator@HintTech-Dev MINGW64 /
$ set | grep ZZZ

Administrator@HintTech-Dev MINGW64 /
$ cat ~/.bashrc
ZZZTESTVAR=234

Administrator@HintTech-Dev MINGW64 /
$ ZZZTESTVAR=234

Administrator@HintTech-Dev MINGW64 /
$ set | grep ZZZ
ZZZTESTVAR=234

Administrator@HintTech-Dev MINGW64 /
$

Why isn't my .bashrc being run? It seems to be in the right place and have the right permissions.

Answer

Jez picture Jez · Aug 24, 2015

OK, I found out the problem. Quite simply, the bash terminal used by the latest Git for Windows 2.5.0 (mintty) doesn't bother to read .bashrc - it reads .bash_profile. So you can set up your environment in .bash_profile and/or put this code at the start to read .bashrc:

if [ -f ~/.bashrc ]
then
    . ~/.bashrc
fi