Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

git - How can I specify custom global gitconfig path?

I'm in a bit of a bind with Git. I'm trying to execute git commit but I need to be able to swtich between ~/.gitconfig1 and ~/.gitconfig2 Is there a command line switch - or anyway to have Git use a different gitconfig file then the ones found at /etc/gitconfig, ~/.gitconfig and .git/config?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I found a way to execute this - it wasn't elegant but it did work - and so far seems to be the only way to get this to work.

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

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

And when executing Git Commit (which is the only command that requires the .gitconfig) I overrode the home path.

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

You can then use alias to do this easily

alias sillygit="HOME=/home/marco/.silly/ git"
sillygit commit -m "silly stuff"

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...