Table of Contents Hide
Before using Git, we need to install Git first. 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
The work of Git needs to call the code of libraries such as curl, zlib, openssl, expat, libiconv, etc., so you need to install these dependent tools first.
On systems with yum (such as Fedora) or systems with apt-get (such as Debian systems), it can be installed with the following command:
Each Linux system can be installed using its package management tools (apt-get, yum, etc.):
The Debian/Ubuntu Git installation command is:
$ apt-get install libcurl4-gnutls-dev libexpat1-dev gettext \ libz-dev libssl-dev $ apt-get install git $ git --version git version 22.214.171.124
If the system you are using 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
We can also download the source package from the official website to install, the latest source package download address: https://git-scm.com/download
Install the dependencies of the specified system:
########## Centos/RedHat ########## $ yum install curl-devel expat-devel gettext-devel \ openssl-devel zlib-devel ########## Debian/Ubuntu ########## $ apt-get install libcurl4-gnutls-dev libexpat1-dev gettext \ libz-dev libssl-dev
Unzip and install the downloaded source package:
$ tar -zxf git-126.96.36.199.tar.gz $ cd git-188.8.131.52 $ make prefix=/usr/local all $ sudo make prefix=/usr/local install
Install on Windows platform
Installing Git on the Windows platform is equally easy. There is a project called msysGit that provides an installation package. You can download the exe installation file from the GitHub page and run:
Installation package download address: https://gitforwindows.org/
After the installation is complete, you can use the command line git tool (already comes with an ssh client), as well as a graphical interface Git project management tool.
Find “Git”->”Git Bash” in the start menu, a Git command window will pop up, and you can perform Git operations in this window.
Install on Mac platform
The easiest way to install Git on the Mac platform is to use the graphical Git installation tool. The download address is:
Git provides a tool called git config, which is specially used to configure or read the corresponding working environment variables.
These environment variables determine how Git works and behaves in various ways. These variables can be stored in three different places:
/etc/gitconfigFiles: Configurations that are common to all users on the system. If
--systemoption is used, it is this file that is read and written.
~/.gitconfigFile: The configuration files in the user directory are only applicable to this user. If
--globaloption is used, it is this file that is read and written.
- The configuration file is in the current project’s Git directory (that is, the
.git/configfile ): The configuration here is only valid for the current project.
- The configuration at each level will override the variable of the same name.
.git/configwill override the configuration in
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, usually
C:\Documents and Settings\$USER.
In addition, Git will also try to find the
/etc/gitconfig file, just look at the directory where Git was installed, and use it as the root directory to locate.
To configure an individual’s username and email address:
$ git config --global user.name "techinplanet" $ git config --global user.email [email protected]
If the –global option is used, the changed configuration file is the one located in your user’s home directory, and all your future projects will use the user information configured here by default.
If you want to use another name or email in a specific project, just remove the
--global option and reconfigure. The new settings are saved in the current project’s
Set the default text editor used by Git, usually
Vim. If you have other preferences, such as Emacs, you can reset them:
$ git config --global core.editor emacs
Difference Analysis Tool
Another common one is which diff analysis tool to use when resolving merge conflicts. For example, to use vimdiff instead:
$ git config --global merge.tool vimdiff
Git understands the output of merge tools such as kdiff3, tkdiff, meld, xxdiff, emerge, vimdiff, gvimdiff, ecmerge, and opendiff.
View configuration information
To check the existing configuration information, you can use the
git config --list command:
$ git config --list http.postbuffer=2M user.name=techinplanet [email protected]
Sometimes you see duplicate variable names, which means they come from different configuration files (like
~/.gitconfig), but in the end Git actually uses the last one.
These configurations can also be seen in ~/.gitconfig or /etc/gitconfig as follows:
The output is as follows:
[http] postBuffer = 2M [user] name = runoob email = [email protected]
You can also directly look up the setting of an environment variable, just follow the specific name, like this:
$ git config user.name techinplanet
In this tutorial we learned about how to install GIT on windows, linux and macos. Along with that we saw multiple configuration options in gitconfig file.