Skip to content
LatchkeyLatchkey home

git config: Usage, Options & Common CI Errors

git config reads and writes the settings that control how Git behaves.

Config drives identity, line endings, and dozens of behaviors. CI usually sets user identity and safe.directory.

What it does

git config reads or writes key/value settings in one of three files: system (--system), global (--global, per user), or local (--local, per repo, the default for writes).

Common usage

Terminal
git config user.email "ci@example.com"
git config --global init.defaultBranch main
git config --get remote.origin.url
git config --global --add safe.directory '*'
git config -l                 # list everything

Options

FlagWhat it does
--global / --local / --systemChoose which config file to use
--get / --get-allRead a value (or all values)
--addAppend a value to a multi-valued key
--unsetRemove a value
-l / --listPrint all settings

Common errors in CI

fatal: detected dubious ownership in repository at '…' - the checkout is owned by a different user than the one running git (common in containers). Fix with git config --global --add safe.directory '<path>' (or '*'). Missing user.email/name triggers the commit identity error.

Using this in CI

CI checkouts are shallow and detached by default, which changes the answer this command gives you. Commands that read history, branch names, or tags need the checkout configured for it.

.github/workflows/ci.yml
- uses: actions/checkout@v4
  with:
    fetch-depth: 0   # history, tags, and git describe all need this

- run: |
    git rev-parse --is-shallow-repository   # expect false
    git rev-parse --abbrev-ref HEAD          # prints HEAD when detached

Frequently asked questions

git config: Usage, Options & Common CI Errors?
Config drives identity, line endings, and dozens of behaviors. CI usually sets user identity and safe.directory.
What it does?
git config reads or writes key/value settings in one of three files: system (--system), global (--global, per user), or local (--local, per repo, the default for writes).
Common errors in CI?
fatal: detected dubious ownership in repository at '…' - the checkout is owned by a different user than the one running git (common in containers). Fix with git config --global --add safe.directory '<path>' (or '*'). Missing user.email/name triggers the commit identity error.

Related guides

References

Run this faster and cheaper on Latchkey managed runners - self-healing included. Start free → 30-day trial · No credit card