Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

Git installation configuration


May 25, 2021 Git


Table of contents


Git installation configuration

We need to install Git before we can use it. Git currently runs on Linux/Unix, Solaris, Mac, and Windows platforms.

Git platform installation package download address is: http://git-scm.com/downloads


Installed on the Linux platform

Git's work requires calling the code for libraries such as curl, zlib, openssl, expat, libiconv, and so on, so you need to install these dependency tools first.

On systems with yum (e.g. Fedora) or on systems with apt-get (e.g. Debian systems), you can install them with the following commands:

Each Linux system can simply use its installation package management tools for installation:

Debian/Ubuntu

The Debian/Ubuntu Git installation commands are:

$ apt-get install libcurl4-gnutls-dev libexpat1-dev gettext \
  libz-dev libssl-dev

$ apt-get install git-core

$ git --version
git version 1.8.1.2

Centos/RedHat

If you are using a Centos/RedHat installation command:

$ yum install curl-devel expat-devel gettext-devel \
  openssl-devel zlib-devel

$ yum -y install git-core

$ git --version
git version 1.7.1

Installed on the Windows platform

Installing Git on a Windows platform is just as easy, with a project called msysGit that provides an installation package to download the exe installation file from the GitHub page and run it:

Installation package download address: http://msysgit.github.io/

Git installation configuration

Once installed, you're ready to use the command-line git tool, which already has its own ssh client, and a Git project management tool with a graphical interface.

When you find "Git" - "Git Bash" in the start menu, a Git command window pops up where you can do Git.


Installed on the Mac platform

The easiest way to install Git on a Mac platform is to use a graphical Git installation tool at:

http://sourceforge.net/projects/git-osx-installer/

The installation interface looks like this:

Git installation configuration



Git configuration

Git provides a tool called git config, which is designed to configure or read the appropriate work environment variables.

These environmental variables determine how Git works and behaves at each stage. T hese variables can be stored in three different places:

  • /etc/gitconfig Configuration that is generally applicable to all users in the system. If you use the --system option when --system git config read and write this file.
  • ~/.gitconfig The profile in the user directory applies only to that user. If you use the --global option when --global git config read and write this file.
  • Profile in the Git directory of the current project (that is, .git/config The configuration here is valid only for the current project. Each level of configuration overrides the same configuration at the upper layer, .git/config /etc/gitconfig

On Windows systems, Git searches for .gitconfig files in the user's home directory. The home directory is $HOME the directory specified by the variable, and is generally a C: . . . documents and Settings $USER.

In addition, Git will try to find /etc/gitconfig files, just to see what directory Git was installed in the first place, as the root to locate.

User information

Configure an individual's user name and email address:

$ git config --global user.name "w3c"
$ git config --global user.email [email protected]

If the --global option is used, the changed profile is the one located in your user's home directory, and all of your projects will use the user information configured here by default.

If you want to use a different name or email in a particular project, simply remove the --global option reconfiguration and save the new settings in the .git/config file for the current project.

The text editor

Set the text editor that Git uses by default, typically Vi or Vim. If you have other preferences, such as Emacs, you can reset:

$ git config --global core.editor emacs

Difference analysis tools

It is also more commonly used to use a difference analysis tool when resolving merge conflicts. F or example, if you want to use vimdiff between words:

$ git config --global merge.tool vimdiff

Git understands the output of combined tools such as kdiff3, tkdiff, meld, xxdiff, emerge, vimdiff, gvimdiff, ecmerge, and opendiff.

Of course, you can also specify how to use the tools you've developed, as you can see chapter 7.

View configuration information

To check for existing configuration information, you can use the config--list command:

$ git config --list
user.name=Scott Chacon
[email protected]
color.status=auto
color.branch=auto
color.interactive=auto
color.diff=auto
...

Sometimes you see duplicate variable names, which means that they come from different profiles (such as /etc/gitconfig and ./.gitconfig), but in the end Git actually uses the last one.

You can also look directly at the settings of an environment variable, as long as you follow a specific name, like this:

$ git config user.name
Scott Chacon