Introduction to Git-Repo-Gerrit-1-Git, installation and configuration

Source: Internet
Author: User
Tags temporary file storage git client version control system
Git Introduction

Git is a distributed version control system. The GIT client does not only extract the latest file snapshot, but completely mirrors the code repository. In this way, any server that works collaboratively can be recovered from a local warehouse from any image. Because every extraction operation is actually a complete backup of the code repository

Install git on Ubuntu: sudo apt-Get install git On Windows: Search for msysgit on the internet, download and install it, and the configuration before running git for the first time is generally on the new system. We need to configure our git work environment first. The configuration only needs to be performed once, and the current configuration will be used in future upgrades. If necessary, you can use the same command to modify the existing configuration at any time.
Git provides a tool called git config (it is actually a git-config command, but you can call this command by adding a name to git .), It is used to configure or read the corresponding work environment variables. These environment variables determine the specific working methods and behaviors of git in each link. These variables can be stored in three different places: 1. /Etc/. gitconfigFile: configurations that are common to all users in the system. If the -- System option is used for git config, the file is read and written. 2. ~ /. GitconfigFile: the configuration file in the user directory only applies to this user. If the -- global option is used for git config, the file is read and written. 3. The configuration file (that is, the configuration file in the GIT directory of the current project) . Git/config in the working directoryFile): the configuration here is only valid for the current project. Each configuration level overwrites the same configuration on the upper layer, so the configuration in. Git/config overwrites the same name variable in/etc/gitconfig.
On Windows, git looks for the. gitconfig file in the user's home directory. The main directory is the directory specified by the $ home variable, which is generally c: \ Documents ents and Settings \ $ user. In addition, git will try to find the/etc/gitconfig file, just to check the directory where git was originally installed and locate it as the root directory.
You need to configure the following before using git:
Git config -- global user. Name "gaoyuan"
Git config -- global user. Email [email protected]
There are other optional configurations, such as the editor used for configuration.
Git config -- global core. Editor Emacs
Another commonly used difference analysis tool is used to solve the merge conflicts. For example, to use vimdiff:
Git config -- Global merge. Tool vimdiff
View git configurations.
Git config -- list
Sometimes we can see repeated variable names, which means they come from different configuration files (such as/etc/gitconfig and ~ /. Gitconfig), but the final git actually uses the last one. You can also directly check the setting of an environment variable, as long as the specific name is followed, like this:
Git config user. Name

For SSH configuration, most git servers use the SSH Public Key for authorization. Every user in the system must provide a public key for authorization. If not, a public key is generated. First, check whether there is a public key. The SSH Public Key is stored in the main directory of the account by default ~ /. Ssh directory (Linux environment). If not, use the command (Linux environment ):
Ssh-keygen
Press enter all the way to create . Ssh folderOpen two files, Id_rsa and id_rsa.pub, . PubIt is the public key, and the other is the private key. The public key must be handed over to the server. The server uses the public key and private key to determine your identity. (We will discuss how to use the public key and Gerrit later)
In Windows, if msysgit is installed, open git bash, enter ssh-keygen, and press Enter. The generated file is in c: \ Users \ USERNAME \. SSH or c: \ Documents ents and Settings \ User Name \. under SSH
Git command alias git does not infer which command will be entered with a few characters. However, if you want to be lazy and try to omit a few characters, you can use git config to set an alias for the command. Let's take a look at the following example:
Git config -- Global alias. CO checkoutgit config -- Global alias.br branchgit config -- Global alias. CI commitgit config -- Global alias. St status
Now, to enter git commit, you only need to type git CI. As git goes deeper, there will be many frequently used commands. In this case, you may wish to create an alias to improve efficiency. Using this technology, you can also create new commands. For example, it is complicated to cancel the temporary file storage. You can set it yourself:
Git config -- Global alias. unstage 'reset head --'
In this way, the following two commands are exactly the same:
Git unstage fileagit reset head filea
Obviously, the alias method looks clearer.
The Git hosting service is easy to understand. if you do not know git yet, I hope you can read the tutorial and tap the command in person. gitHub, or open-source China (oschina) provides a free Git hosting service. You can create a library on it and perform various operations on it.
For open-source China, we recommend that you use HTTPS instead of SSH. for HTTPS access, you must enter the user name and password each time. for https-based submission, if you want to remember the password, you can configure:
Git config -- Global credential. helper store



From Weizhi note (wiz)

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.