Configuration before the first running of Git
Generally, in the new system, we need to configure our git work environment first. The configuration only needs to be performed once, and the current configuration will be used in future upgrades. If necessary, you can use the same command to modify the existing configuration at any time.
Git provides a tool called git config (it is actually a git-config command, but you can call this command by adding a name to git .), It is used to configure or read the corresponding work environment variables. These environment variables determine the specific working methods and behaviors of git in each link. These variables can be stored in the following three different places:
/Etc/gitconfig
File: configurations that are common to all users in the system. If you useGit config
Usage
-- System
This file is read and written.
~ /. Gitconfig
File: the configuration file in the user directory only applies to this user. If you useGit config
Usage
-- Global
This file is read and written.
- The configuration file in the GIT directory of the current project (that is, in the working directory)
. Git/config
File): the configuration here is only valid for the current project. The configuration at each level overwrites the same configuration at the upper layer.
. Git/config
The configuration in will overwrite/Etc/gitconfig
Variable of the same name.
On Windows, git will find. Gitconfig
File. The main directory is$ Home
The directory specified by the variable, usually
C: \ Documents ents and Settings \ $ user
. In addition, git will try to find the/etc/gitconfig file, just to check the directory where git was originally installed and locate it as the root directory.
User Information
The first configuration is your personal user name and email address. These two configurations are very important. Each git commit will reference these two configurations, indicating who submitted the update and will be permanently included in the history together with the updated content:
$ Git config -- global user. Name "John Doe" $ git config -- global user. Email johndoe@example.com
If-- Global
The changed configuration file is located in your user's home directory. In the future, all your projects will use the user information configured here by default. If you want to use another name or email in a specific project, remove
-- Global
Option to re-configure, the new settings are saved in the current project. Git/config
File.
Text Editor
Next, set the default text editor. Git automatically calls an external text editor when you enter some additional messages. By default, the default editor specified by the operating system is used, which may be VI or vim. If you have other preferences, such as Emacs, You can reset them:
$ Git config -- global core. Editor Emacs
Difference Analysis Tools
Another commonly used difference analysis tool is used to solve the merge conflicts. For example, to use vimdiff:
$ Git config -- Global merge. Tool vimdiff
Git can understand the output information of kdiff3, tkdiff, meld, xxdiff, emerge, vimdiff, gvimdiff, ecmerge, and opendiff merging tools. Of course, you can also specify to use your own developed tools. For details, refer to chapter 7.
View configuration information
To check the existing configuration information, you can useGit config -- list
Command:
$ Git config -- listuser. Name = Scott chaconuser. Email = schacon@gmail.comcolor.status = autocolor. Branch = autocolor. Interactive = autocolor. Diff = auto...
Sometimes we can see repeated variable names, which means they come from different configuration files (for example/Etc/gitconfig
And~ /. Gitconfig
), But the final git actually uses the last one.
You can also directly check the setting of an environment variable, as long as the specific name is followed, like this:
$ Git config user. namescott Chacon