how to change gitconfig location?

后端 未结 3 1843
借酒劲吻你
借酒劲吻你 2020-12-19 05:11

I am running this command under windows 7:

git status

Now I am getting this error:

fatal: unable to access \'H:\\/.config/g         


        
相关标签:
3条回答
  • 2020-12-19 05:27

    Git will respect the HOME environment variable to determine the location of the global .gitconfig.

    If asking your domain admin to reset your HOMEDRIVE and HOMEPATH variable back to your local user profile is not an option, you can simply change the HOME variable instead (which is usually unset, so there won’t be a conflict) at the top of your shell to make Git use that location.

    For example, if you’re using Git Bash, you can simply add the following line to the bottom of your shell profile, located at C:\Program Files (x86)\Git\etc\profile:

    export HOME="$USERPROFILE"
    

    (I think $USERPROFILE is still left to the default even if the domain settings change your home drive. Of course, you can always specify a fixed path if that doesn’t work)

    If you are using other shells, you can do similar things, for example in PowerShell:

    $env:HOME = $env:USERPROFILE # or = 'C:\Users\poke\'
    

    Of course, since the variable is unset by default, you could also set it at Windows level in your system configuration. That way, every program would use it automatically.

    Afterwards, all Git commands will automatically look at $HOME\.gitconfig.

    0 讨论(0)
  • 2020-12-19 05:40

    Can I still fix this by changing the config location or creating a new config?

    You can simply change your environment variable HOME, in order to reference an existing local folder

    set HOME=C:\local\path
    

    In that folder, a .gitconfig can be defined in order to have a global git config file.

    The msysgit/msysgit/git-cmd.bat defines it by default to:

    @if not exist "%HOME%" @set HOME=%USERPROFILE%
    
    0 讨论(0)
  • 2020-12-19 05:52

    You need to specify the config file location using git config and the -f option.

    git config -f your_config_file
    
    0 讨论(0)
提交回复
热议问题