git config Command: Configure Git in CI
git config gets and sets configuration values that control Git behavior at the repo, user, or system level.
Fresh CI runners have no identity or credentials configured. Before a job can commit or authenticate, it usually sets user.email, user.name, and a credential helper.
Common flags
--global- write to the per-user config (~/.gitconfig) instead of the repo--local- write to the repository config (the default)--system- write to the system-wide config--add <key> <value>- append a value to a multi-valued key--get <key>- print the value of a key--unset <key>- remove a key
Example
# Set a bot identity so an automated commit succeeds
git config --global user.email "ci-bot@example.com"
git config --global user.name "CI Bot"
# Cache the token for pushes back to the remote
git config --global credential.helper storeIn CI
Commits fail with "Please tell me who you are" until user.email and user.name are set. Use --global on ephemeral runners so the identity applies to every repo in the job. For pushes, configure credential.helper or use a tokenized remote URL.
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 detachedKey takeaways
- Set user.email and user.name before any automated commit, or Git refuses to commit.
- --global is convenient on ephemeral runners since the job owns the whole environment.
- credential.helper lets a job authenticate pushes without re-prompting.