# git config: Usage, Options & Common CI Errors

> git config gets and sets Git configuration at system, global, and local scope. Reference for --global, --get, --add, and identity and ownership errors.

Source: https://latchkey.dev/learn/command-reference/git-config  
Updated: 2026-06-25

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

| Flag | What it does |
| --- | --- |
| --global / --local / --system | Choose which config file to use |
| --get / --get-all | Read a value (or all values) |
| --add | Append a value to a multi-valued key |
| --unset | Remove a value |
| -l / --list | Print 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
```

> `git rev-parse --abbrev-ref HEAD` returns the literal string `HEAD` on a detached checkout rather than a branch name. On GitHub Actions read `github.ref_name` instead; the git command cannot know what it was checked out for.

## FAQ

### 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.

---

Latchkey runs CI/CD that repairs its own failures. Agent entry points: https://latchkey.dev/agent.txt, https://latchkey.dev/openapi.json, https://latchkey.dev/llms.txt
