Git installation configuration
We need to install Git before using Git. Git currently supports Linux/Unix, Solaris, Mac and Windows platforms.
The download address of Git installation package for each platform is: http://git-scm.com/downloads
Installation on Linux platform
Git work requires calling curl, zlib, openssl, expat, libiconv and other library codes, so you need to install these dependent tools first.
On a system with yum (such as Fedora) or apt-get system (such as Debian system), you can use the following command to install:
Each Linux system can be much simpler Use its installation package management tool to install:
Debian/Ubuntu
Debian/Ubuntu Git installation command is:
$ 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 The system used is Centos/RedHat. The installation command is:
$ yum install curl-devel expat-devel gettext-devel \ openssl-devel zlib-devel $ yum -y install git-core $ git --version git version 1.7.1
Installation on Windows platform
It is equally easy to install Git on Windows platform. There is a project called msysGit that provides an installation package. , you can download the exe installation file from the GitHub page and run it:
Installation package download address: http://msysgit.github.io/
After completing the installation, you can use the command line git tool (which already comes with an ssh client), and there is also a graphical interface Git project management tool.
Find "Git"->"Git Bash" in the start menu, the Git command window will pop up, and you can perform Git operations in this window.
Installation on Mac platform
The easiest way to install Git on Mac platform is to use the graphical Git installation tool. The download address is:
http://sourceforge.net/projects/git-osx-installer/
The installation interface is as follows:
Git configuration
Git provides a tool called git config, which is specially used to configure or read the corresponding working environment variables.
These environment variables determine the specific working methods and behaviors of Git in each link. These variables can be stored in three different places:
/etc/gitconfig
File: Configuration that is common to all users in the system. If you use the--system
option when usinggit config
, this file will be read and written.~/.gitconfig
File: The configuration file in the user directory is only applicable to this user. If you use the--global
option when usinggit config
, this file will be read and written.The configuration file in the Git directory of the current project (that is, the
.git/config
file in the working directory): The configuration here is only valid for the current project. The configuration at each level will overwrite the same configuration at the upper level, so the configuration in.git/config
will overwrite the variable with the same name in/etc/gitconfig
.
On Windows systems, Git will look for the .gitconfig file in the user's home directory. The home directory is the directory specified by the $HOME variable, which is usually C:\Documents and Settings\$USER.
In addition, Git will also try to find the /etc/gitconfig file, but it depends on the directory where Git was originally installed, and uses this as the root directory to locate it.
User Information
Configure the personal user name and email address:
$ git config --global user.name "php" $ git config --global user.email test@php.cn
If the --global option is used, then the configuration file to change It is the one located in your user home directory. All your future projects will use the user information configured here by default.
If you want to use a different name or email in a specific project, just remove the --global option and reconfigure. The new settings are saved in the .git/config file of the current project.
Text Editor
Set the text editor used by Git by default, Usually it will be Vi or Vim. If you have other preferences, such as Emacs, you can reset it: :
$ git config --global core.editor emacs
Difference analysis tool
Another commonly used one is which difference analysis tool to use when resolving merge conflicts . For example, if you want to use vimdiff instead:
$ git config --global merge.tool vimdiff
Git can understand the output information of merge tools such as kdiff3, tkdiff, meld, xxdiff, emerge, vimdiff, gvimdiff, ecmerge, and opendiff.
Of course, you can also specify the use of tools developed by yourself. Please refer to Chapter 7 for details on how to do this.
View configuration information
To check existing configuration information, you can use the git config --list command:
$ git config --list http.postbuffer=2M user.name=php user.email=test@php.cn
Sometimes you will see duplicate variable names, then It means that they come from different configuration files (such as /etc/gitconfig and ~/.gitconfig), but in the end Git actually uses the last one.
We can also see these configurations in ~/.gitconfig or /etc/gitconfig, as shown below:
vim ~/.gitconfig
The display content is as follows As shown:
[http] postBuffer = 2M [user] name = php email = test@php.cn
You can also directly check the setting of an environment variable, just follow the specific name, like this:
$ git config user.name php