Skip to content

Git Configuration

Git configuration are stored in 3 layers

1 System:

  • Priority: lowest
  • config file path: /etc/gitconfig
  • Command to edit: git config edit --system

2 Global:

  • Priority: more than system
  • config file path: ~/.gitconfig or ~/.config/git/config
  • Command to edit: git config edit --global

3 Local:

  • Priority: highest
  • config file path: .git/config inside the initialized repo directory
  • Command to edit: git config edit --local or git config edit

Git Configuration Commands

  • git config get - Retrieve a configuration value
  • git config list - List all configurations
  • git config set - Set a configuration value
  • git config unset - Remove a configuration
  • git config edit - Edit configuration file

Note

  • All git config command can have --system or --global or --local based on the layer of configuration needs to be considered.
  • If --global or --system or --local is not used with the command then --local is considerd by default

Git configuration sections

User Section

user - Who is making the commit

Key Values Purpose
user.name Any name Name recorded in commits
user.email Email address Email recorded in commits
user.signingKey GPG/SSH signing key Key used to sign commits/tags
user.useConfigOnly true / false Prevent Git from guessing your name/email
[user]
    name = User Name
    email = [email protected]
    signingKey = ~/.ssh/id_ed25519.pub
    useConfigOnly = true

Info

Option user.userConfigOnly means "Only use the username/email explicitly configured in Git. Don't guess them from the machine/user account."

init Section

init - New repository defaults

[init] options

  • defaultBranch → Name of the first branch. Example: main

  • templateDir → Files/templates to copy when creating a new repo.

  • defaultObjectFormat → Hash format Git uses for commits/files. Example: sha1 or sha256

  • defaultRefFormat → How Git stores branches and tags internally.

Set default branch name when new repository is created

git config --global init.defaultBranch main

core section

core - Fundamental Git behaviour

Controls fundamental Git behavior on your computer.

Config Common Values Simple Explanation
core.editor code --wait, vim, nano Editor Git opens for messages
core.autocrlf true, false, input Handles Windows/Linux line endings
core.fileMode true, false Whether Git tracks executable permission changes
core.excludesFile File path Global ignore file for all repositories

For Visual Studio Code:

git config --global core.editor "code --wait"
For Windows, commonly:
git config --global core.autocrlf true
For Linux/macOS, commonly:
git config --global core.autocrlf input

remote section

remote - Where is the remote repository?

A remote connects your local repository to something like GitHub, GitLab, or Azure DevOps.

Usually the remote is called origin.

Config Example Value Simple Explanation
remote.origin.url Repository URL Where Git fetches/pulls code from
remote.origin.fetch Refspec Defines which remote branches Git fetches
remote.origin.pushurl Repository URL Optional different URL for pushing

Normally you don't configure these manually. For example:

git remote add origin https://github.com/user/project.git

Git creates the corresponding configuration.

branch section

branch - Which remote branch am I tracking?

Connects your local branch to a remote branch.

Config Example Value Simple Explanation
branch.main.remote origin Remote that local main tracks
branch.main.merge refs/heads/main Remote branch that local main tracks
branch.main.rebase true, false Whether this branch should rebase when pulling

For example:

Local main
    ↓ tracks
origin/main

Usually Git sets this automatically when you clone or configure an upstream branch.

fetch section

fetch - Download changes

git fetch downloads information from the remote without integrating it into your current branch.

Config Common Values Simple Explanation
fetch.prune true, false Remove stale remote-tracking branches
fetch.pruneTags true, false Remove stale remote tags

Very useful:

git config --global fetch.prune true

Suppose someone deletes:

origin/old-feature

After fetching, Git can automatically remove that stale remote-tracking reference.

pull section

pull - How should Git pull changes?

Conceptually:

git pull = git fetch + integrate

The important question is how should Git integrate the downloaded commits?

Config Value Simple Explanation
pull.rebase false Use merge when pulling
pull.rebase true Use rebase when pulling
pull.ff only Pull only when fast-forward is possible

For example:

git config --global pull.rebase true

means:

When pulling, rebase my local commits on top of the downloaded commits.

push section

push - How should Git push?

Controls what happens when you simply run:

git push
Config Common Values Simple Explanation
push.default simple Push current branch to its configured upstream
push.default current Push current branch to same-named remote branch
push.autoSetupRemote true, false Automatically configure upstream for a new branch
push.followTags true, false Also push relevant annotated tags

Useful:

git config --global push.autoSetupRemote true

This makes pushing newly created branches more convenient.

merge section

merge - How should conflicts/merges work?

Controls merge behavior.

Config Common Values Simple Explanation
merge.conflictStyle merge, diff3, zdiff3 Controls how merge conflicts are displayed
merge.tool vimdiff, meld, etc. Tool used to resolve merge conflicts
merge.autoStash true, false Temporarily stash changes before merging

Useful setting:

git config --global merge.conflictStyle zdiff3

zdiff3 gives you more context when resolving conflicts.

rebase section

rebase - Rebase behavior

Controls how git rebase operates.

Config Common Values Simple Explanation
rebase.autoStash true, false Temporarily stash changes before rebasing
rebase.autoSquash true, false Automatically organize fixup! and squash! commits
rebase.updateRefs true, false Update related refs after rewriting commits

Useful:

git config --global rebase.autoStash true

credential section

credential - Authentication

Controls how Git gets credentials when connecting to remotes over HTTPS.

Config Common Values Simple Explanation
credential.helper Credential helper Program that securely retrieves/stores credentials
credential.username Username Default username used for authentication
credential.useHttpPath true, false Treat different repository URL paths separately

The actual credential helper depends on your operating system and Git installation.

Don't store passwords or access tokens directly in .gitconfig.

commit section

commit - Commit behavior

Config Common Values Simple Explanation
commit.gpgSign true, false Automatically cryptographically sign commits
commit.verbose true, false Show the diff while writing a commit message

If your organization requires signed commits:

git config --global commit.gpgSign true

diff section

diff - How differences are shown

Controls git diff.

Config Common Values Simple Explanation
diff.tool vimdiff, meld, etc. External program used to view differences
diff.algorithm myers, minimal, patience, histogram Algorithm Git uses to calculate differences
diff.renames true, false Detect renamed files

alias section

alias - Create shortcuts

Aliases let you define shorter Git commands.

Config Value Result
alias.st status git st → git status
alias.br branch git br → git branch
alias.co checkout git co → git checkout
alias.cm commit git cm → git commit

Example:

git config --global alias.st status

Now:

git st

does the same thing as:

git status

Quick Summary

Section What It Controls
user Your commit identity
core Basic Git behavior
remote Connection to remote repository
branch Branch tracking
pull How remote changes are integrated
push How commits are pushed
fetch Downloading remote changes
merge Merge and conflict behavior
rebase Rebase behavior
credential Authentication
init New repository defaults
commit Commit behavior/signing
diff Difference calculation/display
alias Command shortcuts