Git tutorial and Basic Principles

Source: Internet
Author: User

Note: All images of this tutorial are downloaded from Pro Git. Unless otherwise stated, all of the following operations are performed on Linux terminals. If you find any errors or other problems in this article, contact me: wengpingbo # gmail.com.

1. What is GIT?

Git is a speed-oriented distributed version control software and source code management system (SCM ). Git was originally a management software designed for kernel development by Linus Torvalds. Since the launch of Git, it has been adopted by many open-source projects. Each Git working directory is a repository with full history and version information, independent of the network and central server. Git is a free open-source software that complies with the GNU v2 protocol.

The original meaning of Git in English is clumsy and useless. Linus laughed at himself and said, "I am a willful idiot, so I name all my projects very similar to me. The first is Linux, and now it is Git ." Git's help document describes Git as the clumsy content tracker ). (Translated from WIKI)

About the development of Git some historical origins, you can look at this site: https://lkml.org/lkml/2005/4/6/121

2. Why GIT?

 

  • Smoother workflows and full offline operations during development
  • Fast. The Git distributed architecture allows the local repository to contain all historical version information. You can quickly switch between different versions.
  • An elastic local branch. In svn, You need to copy the source code to another folder to build a branch. In Git, the cost of creating a branch is very small. Only one command is required.
  • The repository directory structure is concise. You can use Git to copy a project and only create a. git directory in the project root directory, while other directories are clean.
  • The content is stored in metadata. All version information is stored in the. git directory.
  • Good integrity, easier collaborative development
  • A large user base. There are already thousands of open-source projects using Git for project management, and there are countless code repositories on github.

 

3. install and configure GIT

A) Installation

1. Install from source code

Before installation, you must ensure that the following dependent packages have been installed on your system: curl, zlib, openssl, expat, and libiconv. If your system is Ubuntu, you can install it like this:

Apt-get install curl-devel expat-devel gettext-devel openssl-devel zlib-devel

When all the dependencies have been resolved, you can download the gitsource code from http://git-scm.com/downloadand compile and install the code later:

Tar-zxf git-1. * .tar.gz

Cd git-1 .*.*

Make prefix =/usr/local all

Sudo make prefix =/usr/local install

2. Install

If your system is Linux or Fedora, you can install Git directly using the following command:

Yum install git-core (fedora)

Apt-get install git-core (ubuntu)

3. install on Windows

Although Git originated from Linux, Git can be used normally on Windows, but it does not support Chinese characters. in Windows, all Chinese characters are displayed with question marks. In addition, there are some functional bugs. Therefore, we recommend that you use Git on Linux. If you have to work on Windows, you can download the latest version of msysgit. The installation process is similar to that of other Windows programs, basically, the next step is OK. By default, the git bash and git GUI programs are installed in Msysgit. Generally, you can use git bash, which supports common commands. If you are not familiar with Linux Command lines, you can also use the git GUI, but the features are limited.

B) Use GIT for the first time

After installing Git, You need to modify some configurations to use Git normally.

Git uses the "git config" command to configure Git. This command has two options: -- system, -- global, and the default options, which correspond to three levels of configuration files on Git respectively. The first one is the/etc/gitconfig file, which corresponds to -- system. This is a global configuration file. modifying this file will affect all users and warehouses in the system. The second is the/. gitconfig file in your directory, which corresponds to -- global. modifying it will affect all the repositories of your current user. The third is the. git/. gitconfig file in your repository. This is the default configuration file modified by "git config". It will only affect your current repository.

When you use Git for the first time, you need to tell your co-developers who you are and your email address. When you submit, Git needs the two information. Run the following command to set the parameters:

Git config -- global user. name "Test OSS"

Git config -- global user. email oss.lzu.edu.cn@gmail.com

You can also choose not to use the -- global option, but this means that you must set it in every repository.

You can also specify your editor, your Diff tool:

Git config -- global core. editor vim

Git config -- global merge. tool vimdiff

You can also run the "git config -- list" command to view your settings.

After you set up Git, if you want to obtain a repository from the Git server or submit your code (such as github) to the Git server ), you may need to generate your own ssh key pair. Git supports four protocols for communication with the server: git, http, ssh, and https. Git is only a read-only protocol, that is, you can only obtain the Repository from the server, but you cannot submit your own code. Http and https are rarely used. Most of them only support the ssh protocol and Git protocol.

When you use the ssh protocol to communicate with a remote server, you can use the following command to generate an ssh key pair:

Ssh-keygen-t rsa

If you do not specify the key name and storage path, it places two asymmetric keys under your home directory by default. in the ssh directory, the default names of the key files are id_rsa and id_rsa.pub. The former is the private key and the latter is the public key. In the middle, you may need to set an access key password, which can be set or not. However, we recommend that you set an access key for security considerations. Otherwise, it means that anyone holding your key can use it.

Then, send your public key to the Git repository administrator, and then you can access the server through the ssh protocol. During this period, the program automatically matches the key pair. If you set the access password, you may need to enter the password.

Related Article

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.