How to specify a custom global gitconfig path?

I am a bit attached to Git . I'm trying to execute a git commit , but I need to be able to swtich between ~/.gitconfig1 and ~/.gitconfig2 Is there a command line switch - or in any case have Git use a different gitconfig file, and the one found in /etc/gitconfig , ~/.gitconfig and .git/config ?

+7
git configuration
Aug 28 '10 at 20:34
source share
4 answers

I found a way to accomplish this - it was not elegant, but it really worked - and so far this is the only way to make it work.

Git uses the HOME path to determine where .gitconfig . I was able to execute something like this:

 /home/marco/.silly/.gitconfig /home/marco/.stupid/.gitconfig /home/marco/.gitconfig 

And when doing Git Commit (which is the only command that requires .gitconfig ), I redefined the home path.

 HOME=/home/marco/.silly/ git commit -m "silly configuration" 

Then you can use an alias to make it easy

 alias sillygit="HOME=/home/marco/.silly/ git" sillygit commit -m "silly stuff" 
+12
Aug 29 '10 at 15:07
source share
β€” -

man git-config tells me to use the -f flag to transfer the configuration file. However, it does not work with commands other than git config , so I think you should call it before committing, easily executed with an alias.

0
Aug 28 '10 at 21:00
source share

Mario Ceppi's alias approach can be used in a slightly more elegant way by using the -c config=value argument to git :

 $ alias sillygit="git -c user.name=Silly -c user.email=silly@silly.org" $ sillygit commit 

This, of course, assumes that you do not mind holding different configuration keys in your .bashrc or the like, and not in your .gitconfig , and it has a caveat to cancel shell termination.

0
Oct 19 '17 at 21:42 on
source share

You can use - git-dir

 git --git-dir /home/marco/silly/.git commit ... 
-3
Apr 18 '12 at 21:16
source share



All Articles