简体   繁体   中英

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? Eg, 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.

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 $

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM