Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git for Windows doesn't execute my .bashrc file

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.

like image 428
Jez Avatar asked Aug 24 '15 16:08

Jez


People also ask

How do I run .bashrc on Windows?

Just type notepad ~/. bashrc from the bash prompt and notepad will be launched with this file opened or will ask to create it, if it doesn't exist. If you're comfortable to vim, just type vim ~/. bashrc .

Does Windows have a bashrc?

In windows there is no . bashrc file. But there is a way to achieve the same functionality using powershell. In this example we will download notepad++ and set an alias vim to open files in notepad++ from command prompt.

Is bashrc the same as bash_profile?

bash_profile is read and executed when Bash is invoked as an interactive login shell, while . bashrc is executed for an interactive non-login shell. Use . bash_profile to run commands that should run only once, such as customizing the $PATH environment variable .


3 Answers

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 
like image 100
Jez Avatar answered Sep 21 '22 21:09

Jez


Same thing happened to me when I upgraded to Git Bash 2.5.0 in Windows 10. I renamed my '.bashrc' -> '.bash_profile' and relaunched Git Bash. Everything's working as usual again.

mv ~/.bashrc ~/.bash_profile
like image 32
user932885 Avatar answered Sep 20 '22 21:09

user932885


It appears the latest version of git for Windows (2.8.3.windows.1) uses a 'profile' file now instead of the .bash_profile. I assume this is so it isn't hidden and a valid file name. Didn't seem to cause any issues before, but maybe it was confusing to people.

like image 24
John Livermore Avatar answered Sep 23 '22 21:09

John Livermore