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