How do I override Git configuration options by command line parameters?
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
Introduction
Git lets you override configuration values for a single command by passing -c key=value on the command line. This is useful when you want temporary behavior changes without editing .gitconfig, repository config, or system-wide settings.
Use -c for Temporary Overrides
The basic form is:
For example, you can force a one-off commit identity without changing your saved configuration:
Those values apply only to that Git invocation. They do not permanently modify global or repository config files.
That makes -c ideal for automation, CI jobs, experiments, or edge cases where you need different behavior for exactly one command.
Practical Examples
You can override editor selection:
You can force colored output in a specific context:
You can change HTTP behavior or certificate checks for one network operation, though security-sensitive overrides should be used with caution:
Multiple -c flags may be supplied, and Git evaluates them as high-precedence configuration for that process.
Precedence and Scope
Git configuration normally comes from several places:
- system config
- global user config
- repository local config
- command-line overrides
A -c value sits above the usual file-based configuration for the current invocation. That is why it is so convenient for short-lived changes.
However, the override is still only configuration. It does not rewrite history, change repository state by itself, or bypass the semantics of the command you are running. It simply changes how Git behaves while executing that one command.
When to Use This Instead of git config
Use git config when the setting should persist. Use git -c when the setting is intentionally temporary.
For example:
- CI pipelines often use
-c user.name=...and-c user.email=... - support engineers may temporarily adjust tracing or network behavior
- scripts can stay self-contained without mutating the caller's config files
That last point is important. A script that edits a developer's global Git config is much riskier than a script that supplies temporary overrides inline.
A Few Caveats
Not every configuration idea belongs on the command line. Large values, secrets, or environment-specific settings can become hard to read or leak into process listings. For those cases, environment variables or dedicated config files may be better.
You should also remember that shell quoting rules still apply. Values containing spaces or special characters need proper quoting, otherwise the shell can split or reinterpret them before Git ever sees them.
That is especially relevant in cross-platform scripts, where quoting behavior can differ between shells. A one-line override that works interactively can fail in automation if the value is not passed as a single argument.
Common Pitfalls
- Expecting
-cto persist after the command finishes. - Forgetting to quote values that contain spaces or special characters.
- Using
git configin automation when a one-off-coverride would be safer. - Passing insecure temporary settings such as disabled SSL checks without understanding the risk.
- Assuming command-line overrides change repository data rather than only Git's behavior for that invocation.
Summary
- Use
git -c key=value <command>for one-off configuration overrides. - Supply multiple
-cflags when a command needs several temporary settings. - Prefer
-cover editing config files when the change should not persist. - Be careful with quoting and with security-sensitive temporary settings.
- Think of
-cas a scoped override for one Git process, not a permanent configuration change.
Related reading
- How do I ''overwrite'', rather than ''merge'', a branch on another branch in Git?
- How do I pass a Github secret into kubernetes yaml files using github actions workflow
- How do I prevent 'git diff' from using a pager?
- How do I prevent 'git diff' from using a pager?
- How do I programmatically determine if there are uncommitted changes?
- How do I properly force a Git push?
- How do I provide a username and password when running \"git clone [email\_protected]\"?
- How do I provide a username and password when running git clone email protected?
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.