Configuration

Configuration#

This section overviews ways to configure git utility. Check official description here.


The following cell creates repo that we’ll use as example.

cd /tmp
[ ! -d "dirname" ] && mkdir "dirname"
cd git_config_experiments
git init &> /dev/null

Command#

The git config command is used to manage Git configuration settings via the command line. It interacts with specific configuration files to set or retrieve values.


The following cells show the output of the command, listing the options set for the configuration of the particular repository.

git config --list --local
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true

But all it does is display a toml-like configuration file .git/config that determines the behaviour of the git utility specifically for that repository.

cat .git/config
[core]
	repositoryformatversion = 0
	filemode = true
	bare = false
	logallrefupdates = true

File#

git config is an interface for creating special configuration files. You can modify these files manually, and this section provides an overview of the available options. There is a special section in the official documentation that explains how to manage Git configuration files.

Several files regulate Git’s behavior:

  • System-wide: typically located at /etc/gitconfig.

  • Global: applied to a particular user, typically located at ~/.gitconfig.

  • Local: applied only to the specific repository, typically located at ./.git/config.

  • Worktree: typically located at ./.git/config.worktree.


For example, consider the git configuration in the Docker container created below.

docker run -itd --rm --name git_configuration_files alpine sh -c "
apk update && \
apk add git; 
sh
"
11c771193fb2e35ded342f0d00f7a6ef34bf85e3c84a7095e674f8d2d22b6640

The following cell adds the system configuration file. The resulting configuration file defines an alias for the git echo command to print the system message.

docker exec -it git_configuration_files sh -c 'cat << EOF > /etc/gitconfig
[alias]    
    echo="!echo system"
EOF'

We can check if git has understood the configuration well by listing all available configurations with git config --list.

docker exec git_configuration_files git config --list
alias.echo=!echo system

And it’s really easy to check if created alias works, just by invoking git echo.

docker exec git_configuration_files git echo 
system

We got message system as defined in the configuration file.

docker stop git_configuration_files
git_configuration_files

Variables#

This section covers the options you can use for your configuration. Check the official documentation list. The list of variables is quite extensive, so the following cell includes, in my opinion, only the most important options.

Category

Variable

Description

User

user.name

Defines the name to be used for commits.

user.email

Defines the email address to be used for commits.

Core

core.editor

Specifies the editor to be used by Git commands.

core.autocrlf

Controls automatic line-ending conversion between Windows and Unix systems.

core.safecrlf

Ensures files are checked in with consistent line endings when core.autocrlf is enabled.

core.ignorecase

Determines if Git should ignore case differences in file names.

core.fileMode

Controls whether file permissions are tracked.

core.excludesfile

Specifies the path to a global .gitignore file.

core.hooksPath

Specifies the path to a directory containing custom Git hooks.

Remote

remote.origin.url

URL of the remote repository named origin.

remote.origin.fetch

Defines the refspec for fetching changes from the remote repository named origin.

Branch

branch.<name>.remote

Sets the remote repository for a specific branch.

branch.<name>.merge

Specifies the branch to merge from the remote repository.

Pull/Push

pull.rebase

Determines if git pull should use rebase instead of merge.

push.default

Controls the default behavior of git push (e.g., simple, matching).

Commit

commit.template

Specifies a template file for commit messages.

rebase.autosquash

Automatically squashes fixup and squash commits when rebasing.

Color

color.ui

Enables or disables colored output in Git commands.

Diff/Merge

diff.tool

Defines the diff tool to be used for comparing changes.

merge.tool

Specifies the merge tool to use for resolving merge conflicts.

mergetool.keepBackup

Controls whether Git keeps backup files after a merge resolution.

Alias

alias.<name>

Defines a shorthand alias for Git commands.

Log

log.date

Configures the date format for git log output.

Garbage Collection

gc.auto

Defines when automatic garbage collection should occur based on the number of loose objects.

HTTP

http.sslVerify

Controls whether SSL verification is performed when using HTTPS.

Init

init.defaultBranch

Sets the default branch name when initializing a new repository.

Credential

credential.helper

Specifies a credential helper to use when authenticating with a remote repository.

For some of them find more accurate description in the special page.