Git config: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
 
(49 intermediate revisions by the same user not shown)
Line 1: Line 1:
=Internal=
=Internal=
 
* [[Git_Commands#Configuration_Commands|Git Commands]]
* [[Git#Configuration|Git]]
* [[Git Configuration]]
* [[.gitignore]]
* [[.gitignore]]


=Overview=
=Overview=
 
<code>git config</code> is used to read and manipulate entries in the [[Git_Configuration#Overview|Git configuration files]].
<tt>git config</tt> is used to manipulate entries in Git's configuration files. There are three levels of configuration files, listed below from the highest precedence to the lowest:
 
1. '''file''' (<tt>.git/config</tt>). This file contains repository-specific configuration and has the highest precedence. Repository-specific configuration is manipulated when <tt>git config</tt> is gets the "--file" option. This is the default.
 
2. '''global''' (<tt>~/.gitconfig</tt>). This file contains user-specific configuration and it is manipulated when <tt>git config</tt> gets the "--global" option.
 
3. '''system''' (<tt>/etc/gitconfig</tt>). This file contains system-wide configuration and can be manipulated with the "--system" option, if the user has proper permissions.
 
The configuration files are not replicated during [[git clone]].


More info:
More info:
 
<syntaxhighlight lang='bash'>
git config --help
git config --help
</syntaxhighlight>


=Configuration Operations=
=Configuration Operations=
==List the Configuration==
==List the Configuration==
 
<syntaxhighlight lang='bash'>
git config -l
git config [--system|--global|--local] -l
</syntaxhighlight>
===List the Remote Origin URL===
<syntaxhighlight lang='bash'>
git config --get remote.<origin-name>.url
git config --get remote.origin.url
</syntaxhighlight>


==Configure a Setting==
==Configure a Setting==
<syntaxhighlight lang='bash'>
git config [--system|--global|--file] <some.git.option> <value>
</syntaxhighlight>


git config [--file|--global|--system] <''some.git.option''> <''value''>
<syntaxhighlight lang='bash'>
git config --global push.autoSetupRemote true
</syntaxhighlight>


==Get a Setting==
<syntaxhighlight lang='bash'>
git config --get <some.git.option.name>
</syntaxhighlight>
==Remove a Setting==
==Remove a Setting==
 
<syntaxhighlight lang='bash'>
git config --unset [--file|--global|--system] <''some.git.option''>
git config --unset [--file|--global|--system] <some.git.option>
</syntaxhighlight>
==Remote Manipulation==
See: {{Internal|Git_Concepts#Remote|Remotes}}


=Recipes=
=Recipes=
==Configure the Commit Author==
This command configures the current repository only (<code>--local</code> is implied by default):


==Configure the Commit Author==
<syntaxhighlight lang='bash'>
git config user.name "Ovidiu Feodorov"
git config user.email "ovidiu@example.com"
</syntaxhighlight>


git config user.name "Ovidiu Feodorov"
The configuration propagates to <code>[[.git/config#.5Buser.5D|.git/config [user]]]</code> section.
git config user.email "ovidiu@feodorov.com"


The same effect can be achieved by setting [GIT_AUTHOR_NAME|gitVariables#GIT_AUTHOR_NAME]/[GIT_AUTHOR_EMAIL|gitVariables#GIT_AUTHOR_EMAIL] environment variables.
The same effect can be achieved by setting <code>[[Git_Environment_Variables#GIT_AUTHOR_NAME|GIT_AUTHOR_NAME]]</code> and <code>[[Git_Environment_Variables#GIT_AUTHOR_EMAIL|GIT_AUTHOR_EMAIL]]</code> environment variables.


To configure it for all repositories the user interacts with (if set on a specific repository, that setting will take precedence):
To configure commit author information for all repositories the user interacts with, use <code>--global</code>. If set on a specific repository, the repository-specific setting will take precedence. For more details on configuration hierarchy, see [[Git_Configuration#Overview|Git Configuration]].


{{{
<syntaxhighlight lang='bash'>
git config --global user.name "Ovidiu Feodorov"
git config --global user.name "Ovidiu Feodorov"
git config --global user.email "ovidiu@feodorov.com"
git config --global user.email "ovidiu@example.com"
}}}
</syntaxhighlight>
 
!!!Configuring an Alias


{{{
==Configure an Alias==
<syntaxhighlight lang='bash'>
git config --global alias.show-graph 'log --graph --abbrev-commit --pretty=oneline'
git config --global alias.show-graph 'log --graph --abbrev-commit --pretty=oneline'
}}}
</syntaxhighlight>
 
 
!!!push.default
 
This setting affects the behavior of your local client and only when you don't specify which branches you want to push.
 
It can have two values: "matching" and "simple".
 
"matching" means {{git push}} with no argument will push ''all local branches'' to the ones with the same name on the remote. You don't need to establish any special link between the local branch and the remote branch.
 
This also makes it easy to accidentally push a branch you didn't intend to.
 
"simple" means git push will push only the current branch to the one that git pull would pull from <font color=red>(the link between the local branch and remote branch is established in ...)</font> and also checks that their names match. This is a more intuitive behavior, which is why the default in Git 2.0 is getting changed to this.
 
Recommended value is "simple" - it is safer.
 
!!!Remote Manipulation
 
<font color=red>TODO</font>
 
 
 


=Organizatorium=
==<span id='http.sslVerify'></span>Turn Off SSL Server Certificate Verification for a Specific Repository==


git config --global http.sslVerify true|false
The setting is controlled by <code>http.sslVerify</code> configuration element:
<syntaxhighlight lang='bash'>
cd <repository_dir>
git config http.sslVerify true|false
</syntaxhighlight>
and ends up in modifying <code>.git/config</code>'s <code>[[.git/config#.5Bhttp.5D|[http]]]</code> section as follows:
<syntaxhighlight lang='ini'>
[http]
    sslVerify = true|false
</syntaxhighlight>
The configuration setting is overridden by the <code>[[Git_Environment_Variables#GIT_SSL_NO_VERIFY|GIT_SSL_NO_VERIFY]]</code> environment variable.
==<span id='Configure_url'></span>Configure and Read <tt>[url]</tt> <tt>insteadOf</tt>==
To read:
<syntaxhighlight lang='bash'>
git config --get url."git@github.com:someorg/somerepo".insteadof
</syntaxhighlight>
To configure:
<syntaxhighlight lang='bash'>
git config --global url."git@github.com:someorg/somerepo".insteadof "https://github.com/someorg/somerepo"
</syntaxhighlight>
Also see: {{Internal|Git_Configuration#insteadOf|Git Configuration <tt>url</tt> <tt>insteadOf</tt>}}

Latest revision as of 23:21, 9 January 2024

Internal

Overview

git config is used to read and manipulate entries in the Git configuration files.

More info:

git config --help

Configuration Operations

List the Configuration

git config [--system|--global|--local] -l

List the Remote Origin URL

git config --get remote.<origin-name>.url
git config --get remote.origin.url

Configure a Setting

git config [--system|--global|--file] <some.git.option> <value>
git config --global push.autoSetupRemote true

Get a Setting

git config --get <some.git.option.name>

Remove a Setting

git config --unset [--file|--global|--system] <some.git.option>

Remote Manipulation

See:

Remotes

Recipes

Configure the Commit Author

This command configures the current repository only (--local is implied by default):

git config user.name "Ovidiu Feodorov"
git config user.email "ovidiu@example.com"

The configuration propagates to .git/config [user] section.

The same effect can be achieved by setting GIT_AUTHOR_NAME and GIT_AUTHOR_EMAIL environment variables.

To configure commit author information for all repositories the user interacts with, use --global. If set on a specific repository, the repository-specific setting will take precedence. For more details on configuration hierarchy, see Git Configuration.

git config --global user.name "Ovidiu Feodorov"
git config --global user.email "ovidiu@example.com"

Configure an Alias

git config --global alias.show-graph 'log --graph --abbrev-commit --pretty=oneline'

Turn Off SSL Server Certificate Verification for a Specific Repository

The setting is controlled by http.sslVerify configuration element:

cd <repository_dir>
git config http.sslVerify true|false

and ends up in modifying .git/config's [http] section as follows:

[http]
     sslVerify = true|false

The configuration setting is overridden by the GIT_SSL_NO_VERIFY environment variable.

Configure and Read [url] insteadOf

To read:

git config --get url."git@github.com:someorg/somerepo".insteadof

To configure:

git config --global url."git@github.com:someorg/somerepo".insteadof "https://github.com/someorg/somerepo"

Also see:

Git Configuration url insteadOf