Git adventures (2): install and configure Git

Source: Internet
Author: User
Tags using git version control system

Author of BKJIA Editor's note: Liu Hui, the translator of Git Community Book, told a story about "hello Git" in the previous Git adventure (1): he first came to know the version control system Git. So that many friends have a certain understanding of Git. However, many friends still have many questions about Git. This is the second article of the Git adventure. Starting from this article, Liu Hui will introduce the Linux (* nix) and Windows platforms ,, the following describes how to download, install, and configure Git. The following is the text.

Starting from this article, I will compare the "long-winded" steps of using Git from scratch. Of course, this is also a process for me to re-understand Git.

The first step to use Git is to install Git, because Git is not pre-installed on most platforms. I usually work in windows and Linux (ubuntu) environments. Most of my colleagues who want to read this article also work on these two platforms; next I will explain how to install and configure Git on these two platforms.

BTW: for installation on the Apple platform, refer to (1, 2). The configuration and command line usage are slightly different from those on windows and Linux (* nix) platforms.

Linux (* nix) Platform

The initial goal of Linus to develop Git is to develop the Linux kernel service. Naturally, it provides the best support for the Linux platform. There are several methods to install Git in Linux:

Starting from the source code (this method is also suitable for most * nix platforms)

Download the latest stable version of the source code from the download page of the Git official website. You can start to compile and install the source code:

$ Wget tar-xjvf git-1.7.3.5.tar.bz2 $ cd git-1.7.3.5 $ make prefix =/usr all; # prefix set your Git installation directory $ sudo make prefix =/usr install; # Run with root privileges

To compile the source code of Git, we also need some libraries: expat, curl, zlib, and openssl. In addition to expat, other libraries may be installed on your machine.

Use the Installation Package Manager (apt or yum)

Use yum in systems such as fedora:

$ yum install git-core

Use apt In debian, ubuntu, and other systems:

$ apt-get install git-core

Sometimes, there is a problem with the installation package manager in your system, or the machine that wants to install Git cannot access the Internet or has no compiler, you can download it from the following site. deb "or". rpm installation package:

● RPM Packages

● Stable Debs

Windows Platform

Windows has two tools to simulate * nix like running environment: cygwin and msys; Git has the corresponding porting versions under cygwin and msys. I personally think msysGit on the msys platform is best to use. Now I also use this version in windows.

Many may ask why Git does not directly connect to a windows native version if there are many Git users in windows. I looked at the source code of Git and used a large number of native APIs on the * nix platform, which are not available in windows, therefore, an intermediate layer such as cygwin and msys must be used to meet the Software Porting requirements.

Next, let me explain how to install msysGit in windows.

Download

Go to its download page to download the latest complete installation package, which I downloaded when writing this article.

Install

There is nothing to say about the installation process. Generally, after the installation is started, click "Next ". Because the line breaks (CRLF) on the windows platform are different from those on the Linux (* nix) platform, if you develop software on other platforms in windows, you should pay attention to them (see):

It is best to select the "Checkout as-is, commit as-is" option here, so that Git won't change the line break style of your code.

In the past, a friend selected this option incorrectly, so that when he checked out the code on another platform on windows, the code displayed as "modified" will be displayed ), however, later msysGit may have realized this problem and changed the default option to this option.

BTW: in fact, the first two items are also useful. If you are familiar with how to handle line breaks on windows and Linux (* nix) platforms, you can also try the first two options :)

Configure Git

The method for configuring Git in Linux is similar to that in windows, but in Linux, you can directly use git config in the command line for configuration, in windows, you need to first open "Git Bash", enter the msysGit command line interface, and then use the git config command to perform corresponding configuration operations.

Now, we have installed Git. Now we can configure it:

First, you need to configure the user name and email, because the content will appear in each commit, as shown below:

$ Git log # Use git log to view the commit (commit) log of the current repository commit 71948005382ff8e02dd8d5e8d2b4834428eece24Author: authorDate: Thu Jan 20 12:58:05 2011 + 0800 Project init

The following two commands are used to set the user name and email:

$ Git config -- global user. name author # Set user name to author $ git config -- global user. email author@corpmail.com # Set user mailbox to author@corpmail.com

The configuration information of Git is divided into two types: global and project. The above command includes the "-- global" parameter, which means that the global configuration is in progress, it affects every Git project on the local machine.

As you can see, we use @ corpmail (company email). But sometimes we may also participate in some open-source projects, so we need a new user name and our own private email address, git can set different configuration information for each project.

In the command line environment, go to the directory where the Git project is located and execute the following command:

$ Git config user. name nickname # Set username to nickname $ git config user. email nickname@gmail.com # Set user mailbox to nickname@gmail.com

Git's design philosophy is the same as that of Linux (* nix). It tries its best to use Textuality to store information as much as possible, especially for configuration information, all user configuration information is stored in text files. The global configuration file of Git is stored in "~ /. Gitconfig "(. gitconfig in the user directory) file:

We use the cat and head commands to view the global configuration information file, and assume that the relevant configuration information is stored in the first three lines of the file (of course, it may not be in the first three lines, which is just for convenience)

$ cat ~/.gitconfig | head -3[user]name = authoremail = author@corpmail.com

The project configuration file is stored in the ". Git/config" file in the directory where the git project is located. Here we also use the cat and head commands to check it as above:

$ cat .git/config | head -3[user]name = nicknameemail = nickname@gmail.com

If you are familiar with Git, you can directly modify it "~ /. Gitconfig ",". git/config "are configured.

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.