Dejan
Dejan

Reputation: 1028

Config global user name and email differently for two Git versions on same computer

I have Git installed on my Windows machine and I also have portable git version in folder D:\portableGit on the same machine. I would like that these two versions act independently so that each one have its own config. Currently somehow they share the same config.

For example when I change email from portable version via

git config --global user.email "MyEmailAddressForPortableVersion"

it changes email address also for non-portable git version and vice versa.

I tried to set git HOME folder for portable version hoping that git will store config in that folder. I did that by adding HOME="/myconfig line in D:\portableGit\etc\profile file and now it looks like

....
HOME="/myconfig"
# normalize HOME to unix path
HOME="$(cd "$HOME" ; pwd)"
....

I also create D:\portableGit\myconfig folder, but still both git version share the same global config data.

Upvotes: 0

Views: 90

Answers (1)

Dejan
Dejan

Reputation: 1028

In Windows, you can call Git by opening git-bash.exe or git-cmd.exe depending whether you want to start Git in bash or in cmd.

Depending what you start, Git can search for config file in different location.

To change the path you can do the following:

If you are using git-bash:

You can alter $HOME variable in pathToGit\etc\profile file by adding HOME="/myconfig and then Git will search in pathToGit\myconfig for .gitconfig file where global config settings are stored, exactly as I describe in the question.

If you are using git-cmd:

You need also to change %HOME% but not in etc\profile file. In portable version open file git-cmd.bat, find two lines which looks like

@if not exist "%HOME%" @set HOME=%HOMEDRIVE%%HOMEPATH%
@if not exist "%HOME%" @set HOME=%USERPROFILE%

and remove it. Then define HOME variable inside git-cmd.bat in the following way

set HOME=%git_install_root%\myconfig

if you want that Git search for config file in pathToGit\myconfig folder.

Upvotes: 0

Related Questions