Git Installation and Configuration
Before using Git, we need to install it first. Git currently supports running on Linux/Unix, Solaris, Mac, and Windows platforms.
Download the Git installation packages for various platforms from: http://git-scm.com/downloads
Installation on Linux
Git requires code from libraries such as curl, zlib, openssl, expat, and libiconv, so these dependencies must be installed first.
On systems with yum (e.g., Fedora) or apt-get (e.g., Debian-based systems), you can install using the following commands:
Each Linux system can use its package management tool (apt-get, yum, etc.) for installation:
Debian/Ubuntu
The command to install Git on Debian/Ubuntu is:
$ apt-get install libcurl4-gnutls-dev libexpat1-dev gettext \
libz-dev libssl-dev
$ apt-get install git
$ git --version
git version 1.8.1.2
Centos/RedHat
If you are using a Centos/RedHat system, 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
Source Code Installation
You can also download the source package from the official website for installation. The latest source package can be downloaded from: https://git-scm.com/download
Install the dependencies for 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
Extract and install the downloaded source package:
$ tar -zxf git-1.7.2.2.tar.gz
$ cd git-1.7.2.2
$ make prefix=/usr/local all
$ sudo make prefix=/usr/local install
Installation on Windows
Installing Git on Windows is straightforward. The msysGit project provides an installation package. You can download the exe installation file and run it from the GitHub page:
Download link: https://gitforwindows.org/
If the official site is slow, you can use a domestic mirror: https://npm.taobao.org/mirrors/git-for-windows/.
After installation, you can use the command-line git tool (which comes with an ssh client), as well as a graphical Git project management tool.
Find "Git" -> "Git Bash" in the Start menu to open a Git command window where you can perform Git operations.
Installation on Mac
The easiest way to install Git on Mac is to use the graphical Git installation tool. Download link:
http://sourceforge.net/projects/git-osx-installer/
The installation interface is shown as follows:
Git Configuration
Git provides a tool called git config specifically for configuring or reading corresponding environment variables.
These environment variables determine the specific working methods and behaviors of Git. These variables can be stored in three different places:
/etc/gitconfig
file: Configuration applicable to all users. Usinggit config
with the--system
option reads and writes this file.~/.gitconfig
file: User-specific configuration file. Usinggit config
with the--global
option reads and writes this file.Configuration file in the current project's Git directory (i.e.,
.git/config
in the working directory): This configuration is only valid for the current project. Each level of configuration overrides the same configuration from the upper level, so the configuration in.git/config
overrides the same variables in/etc/gitconfig
.
On Windows, Git looks for the .gitconfig
file in the user's home directory, which is usually C:\Documents and Settings\$USER
.
Additionally, Git tries to find the /etc/gitconfig
file, but it depends on where Git was installed to determine the root directory.
User Information
Configure personal user name and email address:
$ git config --global user.name "tutorialpro"
$ git config --global user.email [email protected]
Using the --global
option changes the configuration file in your home directory, and all your projects will use this user information by default.
If you want to use a different name or email for a specific project, simply reconfigure without the --global
option, and the new settings will be saved in the project's .git/config
file.
Text Editor
Set the default text editor used by Git, which is usually Vi or Vim. If you prefer another editor, such as Emacs, you can reset it:
$ git config --global core.editor emacs
Diff Analysis Tool
Another commonly used setting is the diff analysis tool used to resolve merge conflicts. For example, to switch to vimdiff:
$ git config --global merge.tool vimdiff
Git can understand the output of tools like kdiff3, tkdiff, meld, xxdiff, emerge, vimdiff, gvimdiff, ecm