Configuration before the first running of Git

Source: Internet
Author: User
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/gitconfigFile: configurations that are common to all users in the system. If you useGit configUsage
      -- SystemThis file is read and written.
    • ~ /. GitconfigFile: the configuration file in the user directory only applies to this user. If you useGit configUsage
      -- 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/configFile): the configuration here is only valid for the current project. The configuration at each level overwrites the same configuration at the upper layer.
      . Git/configThe configuration in will overwrite/Etc/gitconfigVariable of the same name.

On Windows, git will find. GitconfigFile. The main directory is$ HomeThe 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-- GlobalThe 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
-- GlobalOption to re-configure, the new settings are saved in the current project. Git/configFile.

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 -- listCommand:

 
$ 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/gitconfigAnd~ /. 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.