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 |
|
Defines the name to be used for commits. |
|
Defines the email address to be used for commits. |
|
Core |
|
Specifies the editor to be used by Git commands. |
|
Controls automatic line-ending conversion between Windows and Unix systems. |
|
|
Ensures files are checked in with consistent line endings when |
|
|
Determines if Git should ignore case differences in file names. |
|
|
Controls whether file permissions are tracked. |
|
|
Specifies the path to a global |
|
|
Specifies the path to a directory containing custom Git hooks. |
|
Remote |
|
URL of the remote repository named |
|
Defines the refspec for fetching changes from the remote repository named |
|
Branch |
|
Sets the remote repository for a specific branch. |
|
Specifies the branch to merge from the remote repository. |
|
Pull/Push |
|
Determines if |
|
Controls the default behavior of |
|
Commit |
|
Specifies a template file for commit messages. |
|
Automatically squashes fixup and squash commits when rebasing. |
|
Color |
|
Enables or disables colored output in Git commands. |
Diff/Merge |
|
Defines the diff tool to be used for comparing changes. |
|
Specifies the merge tool to use for resolving merge conflicts. |
|
|
Controls whether Git keeps backup files after a merge resolution. |
|
Alias |
|
Defines a shorthand alias for Git commands. |
Log |
|
Configures the date format for |
Garbage Collection |
|
Defines when automatic garbage collection should occur based on the number of loose objects. |
HTTP |
|
Controls whether SSL verification is performed when using HTTPS. |
Init |
|
Sets the default branch name when initializing a new repository. |
Credential |
|
Specifies a credential helper to use when authenticating with a remote repository. |
For some of them find more accurate description in the special page.