12

I have the same issue like Git for Windows doesn't execute my .bashrc file and tried to make the same steps. But my Git Bash (2.5.0, 64bit on Windows 7, 64bit) doesn't know my %USERPROFILE%.

pitgrap@xxx MINGW64 /
$ pwd
/

pitgrap@xxx MINGW64 /
$ cd ~
bash: cd: /%USERPROFILE%: No such file or directory

If I run Git Bash as Administror, it works. :( But I don't want to run it everytime as Administrator. Any ideas?

Community
  • 1
  • 1
pitgrap
  • 301
  • 3
  • 11

3 Answers3

9

This just has to do with how each of those different languages handle variable expansion.

cmdC:\> echo %USERPROFILE%
bash: $ echo $USERPROFILE
ps:     PS> echo $env:USERPROFILE

In windows cmd prompt, variables should be surrounded by % on either side
Whereas Bash and PowerShell indicate a variables by prefixing with a $.

Git Bash gets all existing Windows environment variables at startup, while powershell tries to limit polluting the global namespace by including them under the $env object

Shell Comparison

If you want to confirm the shell has access to the environment variable, you can list all variables:

cmd (docs)C:\> SET
bash (docs): $ printenv
ps (docs):     PS> Get-ChildItem env:

KyleMit
  • 30,350
  • 66
  • 462
  • 664
8

The new Git-for-Windows is using a %HOME% enviroment variable. It was set on my machine to HOME=%USERPROFILE%. You can't use another variable here. Remove it or change it to a real path.

See also https://github.com/git-for-windows/git/issues/313

pitgrap
  • 301
  • 3
  • 11
  • After did so, I still got "bash: cd: %userprofile%: No such file or directory ". I am sure I set home = %userprofile% and the keys are generated correctly under the user/user folder. Have no idea still getting this error – Drake .C Feb 20 '19 at 22:02
  • If you set it via the GUI, it will expand `%USERPROFILE%` to its value before saving. To get to the GUI: Start Menu -> Search for "environ" until you see "Edit the system environment variables". `HOME` *must* be set to a path and not a variable reference. – Harvey Oct 27 '21 at 19:57
1

Your syntax is wrong. If you use the Git bash on Windows, you need to write $USERPROFILE instead of %USERPROFILE%.

marius@MYPC MINGW64 ~
$ echo %USERPROFILE%
%USERPROFILE%

marius@MYPC MINGW64 ~
$ echo $USERPROFILE
C:\Users\marius
Marius
  • 41
  • 2