ntc2
ntc2

Reputation: 11912

How to make Git temporarily ignore ~/.gitconfig?

How can I make a Git command temporarily ignore my ~/.gitconfig?

I can set GIT_CONFIG=/dev/null to make git config ignore ~/.gitconfig, but this doesn't affect other Git commands.

I can hide my ~/.gitconfig, e.g. mv ~/.gitconfig{,.hidden}, but this is annoying since I have to move it back later and it affects Git globally.

Use Cases

Upvotes: 22

Views: 2772

Answers (1)

ntc2
ntc2

Reputation: 11912

I found a decent workaround: Git can't use my ~/.gitconfig if it can't find it:

HOME= git <args>

works! Here HOME= effectively unsets HOME for the duration of the command git <args>.

More careful but longer versions include

HOME=/dev/null git <args>

and

(unset HOME; git <args>)

Upvotes: 14

Related Questions