Portable, non-secret Git preferences for setting up a new machine. The tracked
gitconfig contains shared behavior and aliases only. Identity,
signing preferences, credentials, and private keys stay outside this repository.
On a new machine, with nothing checked out yet:
curl -fsSL https://raw.githubusercontent.com/akgagnat/git-config/main/install.sh | shThe installer asks for the name and email to use for commits on this machine. It reads the answers from the terminal, not from standard input, so prompting works even when the script itself arrives on the pipe.
Or, from a checkout:
./install.shThe installer:
- Clones this repository to
${XDG_DATA_HOME:-~/.local/share}/git-configwhen run outside a checkout, and fast-forwards that clone on later runs. Run from a checkout, it uses that checkout instead and clones nothing. - Symlinks the tracked config to
<config dir>/shared.gitconfig, where<config dir>is${XDG_CONFIG_HOME:-~/.config}/git-config. - Adds that stable path as a global Git include without replacing existing global configuration.
- Creates
<config dir>/local.gitconfigfromlocal.gitconfig.example, with owner-only permissions, if it does not already exist, and writes the identity into it.
The shared config includes local.gitconfig by relative path, so it resolves
next to the symlink and follows XDG_CONFIG_HOME automatically. Local values
override the shared configuration and are not tracked by this repository.
Rerunning the installer is safe: the include is added once, and an existing
local.gitconfig is updated in place rather than replaced.
--name NAME Use NAME as user.name instead of asking.
--email EMAIL Use EMAIL as user.email instead of asking.
--no-prompt Never ask; keep whatever identity is already configured.
--ref REF Branch or tag to clone when bootstrapping (default: main).
--uninstall Remove the global include and the shared symlink.
GIT_CONFIG_NAME, GIT_CONFIG_EMAIL, GIT_CONFIG_REPO_URL,
GIT_CONFIG_REPO_REF, and GIT_CONFIG_CLONE_DIR set the same values from the
environment. Pass options through the pipe after -s --:
curl -fsSL https://raw.githubusercontent.com/akgagnat/git-config/main/install.sh |
sh -s -- --name 'Your Name' --email you@example.comWithout a terminal and without those values — in CI, say — the installer skips
the prompt, finishes the rest of the setup, and prints the commands to set the
identity later. Because the shared config sets user.useConfigOnly, Git
refuses to commit until an identity exists, rather than guessing one from your
hostname and login name.
To remove the global include and the symlink, keeping your local identity file and the clone:
./install.sh --uninstallcurl … | sh runs whatever the server returns. That is worth doing only for a
repository you control and over HTTPS, as above. To read the script first:
curl -fsSL https://raw.githubusercontent.com/akgagnat/git-config/main/install.sh -o install.sh
less install.sh
sh install.shThe raw URL serves the public repository without authentication. If the
repository is made private, the URL stops working for curl; clone it over SSH
and run ./install.sh from the checkout instead.
Do not put personal access tokens, passwords, private SSH keys, GPG private
keys, or credential-helper secrets in this repository or in gitconfig.
- Authenticate GitHub CLI separately with
gh auth login. - Store SSH keys under
~/.ssh/with restrictive permissions. - Import GPG private keys into your local keyring; only an optional public key
fingerprint belongs in
local.gitconfig.
Review active configuration and its sources with:
git config --show-origin --listThe shared configuration uses main for new repositories, prunes deleted
remote branches, requires fast-forward pulls, enables rerere, uses zdiff3
conflict markers, and supplies compact status/log aliases. It also sorts
branches by recency and tags by version, enables rebase autoSquash and
updateRefs for stacked branches, pushes tags alongside commits, and turns on
fsckObjects for fetch, receive, and transfer so malformed or malicious
objects are rejected. git log uses a colored format with abbreviated commit
hash, decorations, subject, relative time, and author.
It intentionally does not set an editor, credential helper, signing key, or identity because those are machine- or person-specific.