Changing .gitconfig location on Windows

后端 未结 13 2514
伪装坚强ぢ
伪装坚强ぢ 2020-11-27 11:49

By default on Windows Git places global .gitconfig in c:\\documents and settings\\user\\

How can I change that position so .gitconfig is stored in

13条回答
  •  悲哀的现实
    2020-11-27 12:03

    Solution without having to change Windows HOME variable
    OS: Windows 10
    git version: 2.27.0.windows.1

    I use portable version of Git, so all my config files are on my pen-drive(E:). This is what worked for me:

    1. Download portable Git from https://git-scm.com/. Run the file and install it in the required location. I installed it in E:\git.
    2. Run git-bash.exe from E:\git.
    3. I wanted to put .gitconfig and other bash files in E, so I created a folder called home where I want them all in.
      mkdir home
    4. Go to etc folder and open the file called profile (In my case, it's E:\git\etc\profile)
    5. Add absolute path to the home directory we created (or to the directory where you want to have your .gitconfig file located) at the end of the profile file.
      HOME="E:\git\home"

    Now it no longer searches in the C:\Users directory for .gitconfig but only looks in your set path above.

    $ git config --global --list
    fatal: unable to read config file 'E:/git/home/.gitconfig': No such file or directory
    

    It gave an error because there isn't a .gitconfig file there yet. This is just to demonstrate that we have successfully changed the location of the .gitconfig file without changing the HOME directory in Windows.

提交回复
热议问题