arianit ax
arianit ax

Reputation: 307

change default location of .gitconfig

Running git config --list --show-origin on a Windows 10 machine shows me that the location of .gitconfig is in a remote location. I don't know how it ended there!

enter image description here

I tried few steps to change this from older posts. But with Git 2.30.00 I can't find some of the files or configuration that other StackOverflow Q/A mention. I want to move this to somewhere locally, either D: or my user directory.

The env file that some mention from other questions is like this in my case

export PATH="$HOME/bin:$PATH"

# Allow SSH to ask via GUI if the terminal is not usable
test -n "$SSH_ASKPASS" || {
  case "$MSYSTEM" in
  MINGW64)
    export DISPLAY=needs-to-be-defined
    export SSH_ASKPASS=/mingw64/libexec/git-core/git-gui--askpass
    ;;
  MINGW32)
    export DISPLAY=needs-to-be-defined
    export SSH_ASKPASS=/mingw32/libexec/git-core/git-gui--askpass
    ;;
  esac
}

Upvotes: 3

Views: 8538

Answers (3)

HXavS
HXavS

Reputation: 119

Just want to provide an updated answer since this showed in my google search for "move git config to .config repo"

git added GIT_CONFIG_GLOBAL in version 2.32.0

you can add GIT_CONFIG_GLOBAL=your/custom/config to .zshrc .bashrc to set you global config's new home.

Personally I set mine to .config/git/config

Upvotes: 0

joanis
joanis

Reputation: 12203

TL;DR It might work best to tell Windows globally where you want your HOME

Motivation

While Shaqil's answer should work for you, I expect your strange $HOME variable might cause other problems. On Windows 10, I used to have my HOME set to a network drive when that network drive was visible at boot time, because of my administrator's Windows policies. This created issues not just with Git, but also with other programs that expect to find dot files in my home directory. It also caused a serious slow down of various programs because that network drive had a huge lag when working at home over the VPN.

Solution

My solution was more global: tell Windows that my HOME directory should be local. That fixed both Git and the lag for me, and several other things.

Go to

  • Start Menu /
    • Settings /
      • Search for "variables" /
        • Pick "Edit environment variables for your account"

Then use either "Edit..." or "New..." to set

  • HOME to c:\Users\username
  • HOMEDRIVE to C:
  • HOMEPATH to \Users\username

Although these may seem redundant, some programs rely on HOME, and others on HOMEDRIVE and HOMEPATH, to decide where your HOME is, so you should keep them consistent.

Caveat

Of course, this solution is only appropriate if you want all of your applications see see your home directory on the C: drive.

Upvotes: 1

Shaqil Ismail
Shaqil Ismail

Reputation: 1951

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

set HOME=/local/path

Git by default will use the $HOME environment variable to create the location of the global .gitconfig file.

There is also another way, without making changes to the $HOME variable, by creating an alias which overrides the $HOME variable. More information on this on the following webpage, How can I specify custom global gitconfig path?

Upvotes: 3

Related Questions