19

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

  • Scripting Git: restrict to default settings for portability.
  • Debugging Git: restrict to default settings for reproducibility.
5
  • 1
    Why do you want to do it? What is your use case?
    – Sigi
    May 1, 2014 at 0:47
  • @Sigi: right now I'm debugging Git, and in the past I've wanted this when scripting Git.
    – ntc2
    May 1, 2014 at 0:54
  • 1
    Amazingly, there does not seem to be an option to git which would make it ignore the config(s). Maybe you should submit a request to the Git maintainers to include that possibility.
    – Sigi
    May 1, 2014 at 1:11
  • asked here: groups.google.com/forum/#!topic/git-users/1ehWsItL8vE not sure whether it's the right place; btw the feature should be: override the location, not ignore it; override is more powerful and includes ignoring (by specifying an empty file for eg). Suggested command: git --gitconfigfile=~/.gitconfig_temp diff Aug 2, 2019 at 19:55
  • I've now also asked here: public-inbox.org/git/… Mar 19, 2020 at 5:50

1 Answer 1

10

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>)
3
  • More precisely, it sets HOME to the empty string. May 9, 2014 at 23:52
  • 1
    This might break versions of git before 1.8.4; see Documentation/RelNotes/1.8.4.txt in the git source tree. And git config files (such as <repo>/.git/config) can refer to $HOME or ~. May 10, 2014 at 0:00
  • @KeithThompson: I guess you are referring to "When $HOME is misconfigured to point at an unreadable directory, we used to complain and die. Loosen the check." in the release notes. Thanks!
    – ntc2
    May 10, 2014 at 3:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.