Git Adventures (ii) installation and configuration of--git

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

Fellow students, the Last Git Adventures (a) told a "Hello Git" little story. Some students may have played other distributed version control system (DVCS), after reading the comprehend by analogy to git on the chest, but also some students may be as I started git, it still can not touch the mind.

From this beginning, I will be more "verbose" with everyone from the beginning to experience the use of git every step, of course, for me this is a re-understanding of the process of git.

The first step in using Git must be to install Git, because git is not preinstalled on most platforms. My main working environment is Windows and Linux (Ubuntu), I would like to read this article, most of the students are also working under these two platforms; let me tell you how to install and configure git on these two platforms.

BTW: If the installation of the Apple platform users can see here, the use of configuration and command line with the Windows, Linux (*nix) platform is not very different.

Linux (*nix) platform

The original purpose of Linus development of GIT is to develop the Linux kernel service, and it is also the best platform support for Linux. There are several ways to install Git under Linux:

Start with 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 website, and you can start compiling and installing from the source code:

$ wget http://kernel.org/pub/software/scm/git/git-1.7.3.5.tar.bz2$ tar-xjvf git-1.7.3.5.tar.bz2$ cd git-1.7.3.5$ make PREFIX=/USR all; # prefix set your git install directory $ sudo make prefix=/usr install; # Run as Root

In order to compile Git's source code, we also need some libraries: expat, curl, zlib and OpenSSL, except expat, other libraries may be installed on your machine.

Using the installation Package Manager (APT or yum)

Use Yum in systems such as Fedora:

In Debian, Ubuntu and other systems using apt:

$ apt-get Install Git-core

Sometimes, there is a problem with the installation package Manager in your system, or you can download the ". Deb" or ". RPM" installation package from the following site if you are unable to install a git machine that is not online or has a compiler:

    • RPM Packages
    • Stable Debs
Windows platform

The Windows platform has two tools that mimic the *nix like run environment: Cygwin,msys;git has the appropriate porting version under Cygwin,msys. I personally feel that the msysgit under the Msys platform is best used, and now I am using this version under Windows.

Many students may ask, now there are many Git users under Windows, why git does not directly out of a Windows native version. I looked at Git source code, it used a lot of *nix platform native API, and these APIs are not in Windows, so you have to use a Cygwin, msys such a middle tier to meet the requirements of software porting.

Below i "wordy" How to install Msysgit under Windows.

Download

Go to its download page to download the latest complete installation package, which I downloaded at the moment I wrote this article.

installation

There is nothing to say in the installation process, which is usually started after installation, all the way to the click "Next". Because of the different line breaks (LF) of the Windows platform's newline characters (CRLF) and the Linux (*nix) platform, there is a place for friends who develop other platform software under Windows to be aware of (see):

One of the best choices here is "Checkout As-is, Commit as-is", so git doesn't change the line-break style of your code.

There was a friend who had chosen the wrong option so that his code in a checkout (checkout) other platform under the Windows platform would show "modified" (modified), but then it might msysgit to recognize the problem and change the default option to this option.

BTW: Actually the previous two items are also useful, if you are familiar with how the Windows and Linux (*nix) platform handles line breaks, you can also try the previous two options:)

Configure Git

Under Linux and under Windows to configure Git's approach, just under Linux, you can use git config directly in the command line, and in Windows you will first open "Git Bash", go to the msysgit command line interface, and then git Config command to perform the appropriate configuration operation.

OK, Git is installed in the front, and now we're ready to configure:

The first thing that needs to be configured is the user's username and email, because the content will appear in every commit, like this:

$ git log #我们用git log view commit log for current warehouse commit 71948005382ff8e02dd8d5e8d2b4834428eece24author:author <[email Protected]>date:thu Jan 12:58:05 +0800project Init

The following two lines of command are to set the user name and email:

User.email [email protected] #将用户邮箱设为 [email protected]

Git configuration information is divided into global and project two, the above command with the "--global" parameter, which means that the global configuration, it will affect every GIT project on this computer.

As you can see, we are using @corpmail (company email), but sometimes we may also be involved in some open source projects, then we need a new username and your own private mailbox, Git will 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# user name to nickname$ git config user.email [email protected] #将用户邮箱设为 [email protected]

Git's design philosophy, like Linux (*nix), uses "textual" (textuality) as much as possible, storing information in textual form as much as possible, and more so for configuration information, all of which are stored in a text file. The global configuration file for git is stored in the "~/.gitconfig" (. gitconfig) file in the user directory:

We use the cat, Head command to view the global configuration information file, and assume that the relevant configuration information is stored in the first 3 rows of the file (it may not be in the first 3 lines, this is just for the convenience of presentation)

$ Cat ~/.gitconfig | head-3 [user]name = Authoremail = [email protected]

The project configuration file is stored in the ". Git/config" file in the directory where the Git project resides, and is also viewed as above with the cat and head commands:

$ cat. Git/config | Head-3[user]name = Nicknameemail = [email protected]

If you are familiar with Git, you can directly modify the "~/.gitconfig", ". Git/config" These two files to configure.

Git also has a lot of places to configure, so you can refer to git config and custom git.

This one is a bit bland, but it's a first step for a git user. I will also have a series of articles in the back, all of my personal use of the process of sentiment.

A friend asked me: "Why the article is called: ' Git Adventures '." That's because I've had more than n problems with git, and I think it's a little bit complicated. But when these problems are solved, they sometimes have to marvel at the ingenuity of the design.

If you have any questions and suggestions for my article, please write to me:

Before I set up a git Chinese user group, if you have any trouble with git, you are welcome to ask questions in this user group.

Git Adventures (ii) installation and configuration of--git

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.