stephjang
stephjang

Reputation: 959

Is there a way to unset a global git config section in a local git config file?

My ~/.gitconfig contains this include section to inherit from a team-wide config file.

[include]
    ~/.gitconfig.team

However, I have personal repos where I don't want to inherit from this .gitconfig.team.

Is there a way I can override/force unset this section in my personal repos? E.g., something I can add to .git/config in personal_project/?

I'm interested in a solution where I modify configs in my personal repos instead of my team repos.

Upvotes: 4

Views: 1236

Answers (2)

Claw
Claw

Reputation: 767

As of git 2.13, you can use conditional configuration includes in order to achieve what you're asking.

For instance, if you keep your personal repos in a particular directory, you could introduce a git config to override the entries in your team configuration:

[include]
    ~/.gitconfig.team
[includeIf "gitdir:personal_project/"]
    ~/.gitconfig.personal

Alternatively, if you keep your team repos in a particular directory, you could instead just change your team configuration to use includeIf instead of include:

[includeIf "gitdir:team_project/"]
    ~/.gitconfig.team

Upvotes: 0

AD7six
AD7six

Reputation: 66170

No

Git config includes operate:

as if its contents had been found at the location of the include directive

ref

That means you can't override/remove the include itself, as as soon as it's found the contents of the included file are injected/loaded.

You can of course override the settings it contains in a more specific config file:

# ~/.git.config.team
[user]
    name = name

Locally, via git config user.name nic

# /some/project/.git/config
[user]
    name = alias

Yielding:

/some/project $ git config user.name
alias
/some/project $

Upvotes: 1

Related Questions