Developers learn Linux (9): CentOS7 Compile and install Git-2.13.1 and use

Source: Internet
Author: User
Tags svn using git git clone git shell

1. Preface
In the previous article, we described how to compile and install Subversion1.9.5 and Apache2.4.25 on CentOS7, and integrate with Apache2.4.25 to achieve the effect of centralized authorization control in multiple SVN repositories. Using SVN as a source version tool in a traditional enterprise is relatively high, but many internet companies are already using git as the Source Code versioning tool. The online comparison of SVN and Git is a lot of, one of the most important difference is that SVN is centralized, git is distributed, such as to see the repository of historical commit records, in SVN must be able to connect to the SVN server can be, and in git do not need to do so, The main reason is because it is distributed, only need to work with them to submit the code to the central server or download from the central server to local, under normal circumstances can be submitted locally.
This article is about how to compile and install the latest version of Git under CentOS7.
2. Preparation
Git-2.13.1.tar.gz:git Linux version: https://www.kernel.org/pub/software/scm/git/git-2.13.1.tar.gz, of course, can also be in https:// www.kernel.org/pub/software/scm/git/download other versions.
Git-2.13.1-64-bit.exe:git 64-bit OS version under Windows: https://github.com/git-for-windows/git/releases/download/ V2.13.1.windows.1/git-2.13.1-64-bit.exe
Git-2.13.1-32-bit.exe:git 32-bit OS version under Windows: https://github.com/git-for-windows/git/releases/download/ V2.13.1.windows.1/git-2.13.1-32-bit.exe
Tortoisegit-2.4.0.2-32bit.msi:tortoisegit 32-bit version of Windows,: https://download.tortoisegit.org/tgit/2.4.0.0/ Tortoisegit-2.4.0.2-32bit.msi
Tortoisegit-2.4.0.2-64bit.msi:tortoisegit 64-bit version of Windows,: https://download.tortoisegit.org/tgit/2.4.0.0/ Tortoisegit-2.4.0.2-64bit.msi
Tortoisegit-languagepack-2.4.0.0-32bit-zh_cn.msi:tortoisegit 32-bit version of the Chinese Language pack,: https:// Download.tortoisegit.org/tgit/2.4.0.0/tortoisegit-languagepack-2.4.0.0-32bit-zh_cn.msi
Tortoisegit-languagepack-2.4.0.0-64bit-zh_cn.msi:tortoisegit The Chinese language pack for the 64-bit version of Windows:
Https://download.tortoisegit.org/tgit/2.4.0.0/TortoiseGit-LanguagePack-2.4.0.0-64bit-zh_CN.msi
In the above 7 files, you only need to place git-2.13.1.tar.gz in the CentOS7/root directory, and git-2.13.1-64-bit.exe/ Git-2.13.1-32-bit.exe and tortoisegit-2.4.0.2-32bit.msi/ Tortoisegit-2.4.0.2-64bit.msi and tortoisegit-languagepack-2.4.0.0-32bit-zh_cn.msi/ Ortoisegit-languagepack-2.4.0.0-64bit-zh_cn.msi Select Install based on whether the Windows system is 32-bit or 64-bit.
3. Compiling the installation
3.1 Preparation
In the source of CentOS7 is self-contained git, that is, we can be installed through the Yum install directly, but the version is low, is git-1.8.3.1, we can be viewed through Yum info git, is to see the effect:
650) this.width=650; "title=" Git01_yum_version.png "src=" https://s4.51cto.com/wyfs02/M02/9B/CD/ Wkiom1lnm9gggzutaabxusl7c0a988.png-wh_500x0-wm_3-wmp_4-s_2276490792.png "alt=" Wkiom1lnm9gggzutaabxusl7c0a988.png-wh_50 "/>
The official version of the GIT website is now 2.13, in order to experience the latest version of Git, you need to download the source code from the official website to compile and install.

Consider that there are some dependencies on third-party libraries during the compilation and installation of Git, so the dependent libraries are installed first:
Yum install AsciiDoc docbook2x xmlto texinfo sgml2xml autoconf openjade-y
Yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel gcc perl-extutils-makemaker-y

After the installation is complete, uninstall the old git version:
Yum Remove git

650) this.width=650; "title=" Git02_yum_remove.png "src=" https://s1.51cto.com/wyfs02/M01/9B/CD/ Wkiom1lnm-dsrnosaabiv2tfw04024.png-wh_500x0-wm_3-wmp_4-s_649114549.png "alt=" Wkiom1lnm-dsrnosaabiv2tfw04024.png-wh_50 "/>3.2 Compiling and installing Git-2.13.1
Cd/root
Tar-zxvf/root/git-2.13.1.tar.gz
Cd/root/git-2.13.1/
Make Configure
./configure--prefix=/usr/local/git-2.13.1
Make all doc
Make install Install-doc install-html
If it doesn't go wrong, the above command has already installed git in the/usr/local/git-2.13.1 directory.

4. Configuration
4.1 Configuring the environment variables for git
To facilitate the execution of GIT-related commands in the future, we can add the GIT installation path information to the/etc/profile file, adding the git_home environment variable first:
Export git_home=/usr/local/git-2.13.1
Then edit the PATH environment variable to add git installation path information:
Export path= $PATH: $GIT _home/bin
Then reload the environment variable settings information:
Source/etc/profile
You can use the following command to check that the configuration is correct:
Git–version
which git
The first command above is to view the current version of Git, and the second is to see the executable in which directory executes GIT-related commands at the command line.
4.2 Creating a git run user and usergroup
In the CentOS7 of some git directory and file permissions are very demanding, I have been a lot of configuration is unsuccessful, in order to reduce the situation, we first create a git user and usergroup, and then the user to configure Git. Here are the commands:
Groupadd git
Useradd git-g git
You also need to set the login password for the git user:
passwd git
Install prompt two times enter a consistent password to complete the git user's password settings.
To ensure that the GIT user has sufficient privileges to execute the command we will execute later, we will temporarily add it to sudoer (note that after the configuration is complete or remove the line) so that it can execute the command in sudo, by opening the/etc/sudoers file, In the root user's line, add the Git user, as shown in:
650) this.width=650; "title=" Git03_git_csudoers.png "src=" https://s5.51cto.com/wyfs02/M01/9B/CC/wKioL1lnM_ Gwzjflaabcxxtg17w681.png-wh_500x0-wm_3-wmp_4-s_282739348.png "alt=" wkiol1lnm_gwzjflaabcxxtg17w681.png-wh_50 "/ >
Note that when you use Vim to edit the/etc/sudoers file, you need to use ": wq!" when saving To save the file, rather than the usual ": Wq".
4.3 Configure git user password-free login
Now we switch to the GIT user:
Su git
Now we can login to this machine via SSH command, the command is as follows:
SSH [email protected]
The first time you use this command you will see a hint:
The authenticity of host ' localhost ' (:: 1) ' can ' t be established.
ECDSA key fingerprint is aa:21:ce:7a:b2:06:3e:ff:3f:3e:cc:dd:40:38:64:9d.
Is you sure want to continue connecting (yes/no)?
Entering "Yes" will require you to enter a git user's login password, then ssh to the current machine, if you want to exit the SSH login input "exit" command, as follows:
[[email protected] ~]# su git
[Email protected] root]$ CD ~
[Email protected] ~]$ pwd
/home/git
[[email protected] ~]$ ssh [email protected]
The authenticity of host ' localhost ' (:: 1) ' can ' t be established.
ECDSA key fingerprint is aa:21:ce:7a:b2:06:3e:ff:3f:3e:cc:dd:40:38:64:9d.
Is you sure want to continue connecting (yes/no)? Yes
warning:permanently added ' localhost ' (ECDSA) to the list of known hosts.
[email protected] ' s password:
Last Login:thu Jul 13 11:19:16 2017
[[Email protected] ~]$ exit
Logout
Connection to localhost closed.
[Email protected] ~]$

The above operation or require us to SSH login to the machine needs to enter the user password, through the following configuration can be achieved without password login.
Execute the Ssh-keygen as a git user, enter in the process of execution, and eventually generate Id_rsa and id_rsa.pub two files in the/home/git/.ssh directory.
Then create the Authorized_keys file with the following command:
Touch ~/.ssh/authorized_keys && chmod ~/.ssh/authorized_keys
Authorized_keys is used to store the user's public key for password-free login, the next step is to put the contents of the public key file id_rsa.pub just generated into the Authorized_keys file by the following command:
Cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
After this setting, SSH [email protected] will not be required to enter the user name and password in the future.
4.4 Creating a git repository
Create a directory of Git repositories with the following commands (note using SU git to switch to git users to execute):
sudo mkdir/var/git
sudo chown-r git:git/var/git
Cd/var/git
Git init--bare test.git
The following output is seen when executing the git init--bare test.git command:
Initialized Empty Git repository in/var/git/test.git/
At this point, we have a git repository, and the repository is stored in the/var/git/test.git path.
5. Inspection configuration
5.1 Installing Git-2.13.1.2
Because my notebook uses the Win7 X64 system, so the installation is Git-2.13.1.2-64-bit.exe, according to the software default settings all the way next. After the installation is complete, you can see the Git menu in the Start menu.
5.2 Installing tortoisegit and Tortoisegit-languagepack
Because the Git-2.13.1.2 only provides simple and straightforward operation, it is recommended to install Tortoisegit and tortoisegit-languagepack for ease of operation. It is also installed with the default settings Tortoisegit and Tortoisegit-language Pack.
5.3Git Client Operation
5.3.1 from the server clone repository
Here is an example of the Test.git repository you just created.
Select a working partition in Windows system, right click, the following menu appears:
650) this.width=650; "title=" Git04_git_clone.png "src=" https://s4.51cto.com/wyfs02/M02/9B/CD/ Wkiom1lnnbbyod0eaabeitbyeoq656.png-wh_500x0-wm_3-wmp_4-s_2602328400.png "alt=" Wkiom1lnnbbyod0eaabeitbyeoq656.png-wh_50 "/>
Select the "Git Clone ..." command and the following menu appears:
650) this.width=650; "title=" Git05_git_tortorise_clone.png "src=" https://s5.51cto.com/wyfs02/M02/9B/CC/ Wkiol1lnncsz0fvsaacjbeqfkio218.png-wh_500x0-wm_3-wmp_4-s_655404709.png "alt=" Wkiol1lnncsz0fvsaacjbeqfkio218.png-wh_50 "/>
Then click "OK" to confirm, pop-up password input box, because it is the GIT account login, so you need to enter the GIT user settings just created password, as shown in:
650) this.width=650; "title=" Git06_git_tortorise_clone_password.png "src=" https://s3.51cto.com/wyfs02/M01/9B/CD/ Wkiom1lnndtyc0c-aacc1kdvbum378.png-wh_500x0-wm_3-wmp_4-s_398130271.png "alt=" Wkiom1lnndtyc0c-aacc1kdvbum378.png-wh_50 "/>
It is important to note that if you do not have the correct settings, you will see the following error message:
Fatal:protocol Error:bad Line Length Character:bash
Git did not exit cleanly (exit code 128)
Such as:
650) this.width=650; "title=" Git06_git_tortorise_clone_error.png "src=" https://s5.51cto.com/wyfs02/M02/9B/CD/ Wkiom1lnneldx0qpaabm5oj7ubm935.png-wh_500x0-wm_3-wmp_4-s_1136006622.png "alt=" Wkiom1lnneldx0qpaabm5oj7ubm935.png-wh_50 "/>
The reason for this is that the shell used by the GIT user is not properly set, the shell used by the user is/bin/bash by default, and here we need to modify it to/usr/local/git-2.13.1/bin/git-shell, the above information Modified in/etc/passwd:
Before modification:
Git:x:1002:1002::/home/git:/bin/bash
After modification:
Git:x:1002:1002::/home/git:/usr/local/git-2.13.1/bin/git-shell
Correct the correction and then do the above operation will not error. With the above settings, git users can use git normally via SSH, but cannot log in to the shell because the Git-shell we specify for git users automatically exits every time you log in.
In addition, we temporarily gave the git user the sudo permission in front of it, then we can also cancel this permission setting.
5.3.2 Submitting code to the local repository
Create a file in your local Git working folder and edit the contents of the file, right-click on the folder, and select "Git Commit," "Master" in the pop-up menu, as shown in the way:
650) this.width=650; "title=" Git07_git_tortorise_commit.png "src=" https://s2.51cto.com/wyfs02/M02/9B/CC/ Wkiol1lnnfhc_nlyaabdz4atgmg516.png-wh_500x0-wm_3-wmp_4-s_421401020.png "alt=" wkiol1lnnfhc_ Nlyaabdz4atgmg516.png-wh_50 "/>
In the popup dialog box, select the file to submit and fill in the commit log as shown in:
650) this.width=650; "title=" Git08_git_tortorise_commit.png "src=" https://s4.51cto.com/wyfs02/M01/9B/CD/ Wkiom1lnnglwi2w9aadhb3syn0c477.png-wh_500x0-wm_3-wmp_4-s_2507537758.png "alt=" Wkiom1lnnglwi2w9aadhb3syn0c477.png-wh_50 "/>
Click "Commit" to complete the submission to the local repository, as shown in:
650) this.width=650; "title=" Git09_git_tortorise_push.png "src=" https://s2.51cto.com/wyfs02/M00/9B/CC/ Wkiol1lnnhfyidmhaabz7tnng-s641.png-wh_500x0-wm_3-wmp_4-s_2490628610.png "alt=" Wkiol1lnnhfyidmhaabz7tnng-s641.png-wh_50 "/>
5.3.3 Submitting code to the central repository
The above action is only submitted to the local repository, it is applicable to the local to do some pre-research work, to achieve a phased result can be submitted periodically, if not satisfied with the local revocation of the submission. If you have completed all of the pre-research work in a development team, you need to commit to the central repository so that other members of the same team can get updates.
It's also easy to submit code to the central repository. Right-click on the local Git working folder and select "Tortoisegit, Push ...", as shown in:
650) this.width=650; "title=" Git10_git_tortorise_push_context.png "src=" https://s1.51cto.com/wyfs02/M00/9B/CD/ Wkiom1lnnific8raaacdvbdvbmc625.png-wh_500x0-wm_3-wmp_4-s_4197753872.png "alt=" Wkiom1lnnific8raaacdvbdvbmc625.png-wh_50 "/>
Then it pops up the submission configuration interface, as shown in:
650) this.width=650; "title=" Git11_git_tortorise_push_config.png "src=" https://s5.51cto.com/wyfs02/M01/9B/CC/ Wkiol1lnnjetyquwaacpx7neiku606.png-wh_500x0-wm_3-wmp_4-s_328818199.png "alt=" Wkiol1lnnjetyquwaacpx7neiku606.png-wh_50 "/>
When you click "OK", you will be asked to enter the password of the GIT user and you will see the following screen after entering the password:
650) this.width=650; "title=" Git12_git_tortorise_push_complete.png "src=" https://s2.51cto.com/wyfs02/M00/9B/CD/ Wkiom1lnnkibjtbgaab0vw8rk0y768.png-wh_500x0-wm_3-wmp_4-s_3695323343.png "alt=" Wkiom1lnnkibjtbgaab0vw8rk0y768.png-wh_50 "/>
5.3.4 View commit history
Click the right mouse button on the GIT working folder and select "Tortoisegit-Show log" To view the previous commit record, as shown in:
650) this.width=650; "title=" Git13_git_tortorise_history.png "src=" https://s2.51cto.com/wyfs02/M01/9B/CD/ Wkiom1lnnljramvbaac4-qh14og335.png-wh_500x0-wm_3-wmp_4-s_1692569276.png "alt=" Wkiom1lnnljramvbaac4-qh14og335.png-wh_50 "/>

5.4 Precautions
5.4.1TortoiseGit Password-free submission problem
The Windows client can also generate Id_rsa and id_rsa.pub files from the Ssh-keygen program provided by the GIT native program, importing id_rsa.pub into the ~/.ssh/authorized_keys file on the server, Password input is free when using native git operations, but not when using Tortoisegit. If you want to use tortoisegit without entering a password, you need to import its generated public key into the ~/.ssh/authorized_keys file on the server.
The steps are as follows:
1. Open the git bash command that comes with native git, and select "Git–git Bash" from the Start menu.
2. Enter the "Ssh-keygen" command on the Open command line to generate a public and private key for Git, which is stored under the current user's working path by default. Under the SSH path, such as my Windows system user name is Zhou.jin-qiao, the resulting file path is: C : \users\zhou.jin-qiao\.ssh
3. Open the Tortoisegit with the PuTTYgen command, you can select "Tortoisegit-puttygen" from the Start menu, then click on the "Load" button on the interface, and then select the private key generated in the second step, you will see the following interface when the import succeeds:
650) this.width=650; "title=" Git14_git_tortorise_load.png "src=" https://s5.51cto.com/wyfs02/M02/9B/CD/ Wkiom1lnnmnh0cpiaadl32yar9q481.png-wh_500x0-wm_3-wmp_4-s_436640920.png "alt=" Wkiom1lnnmnh0cpiaadl32yar9q481.png-wh_50 "/>
4. Click the "Save private Key" button to save it to the 2nd step where git holds the public and private key path, where the private key used by C:\users\zhou.jin-qiao\.ssh,tortoisegit has a PPK suffix.
5. Upload the C:\Users\zhou.jin-qiao\.ssh\id_rsa.pub file to the CentOS7 tmp directory, and then import the public key by using the following command:
Cat/tmp/id_rsa.pub >> ~/.ssh/authorized_keys
6. Open the Tortoisegit with the pageant command, you can select "Tortoisegit-pageant" in the Start menu, this program is started by default minimized in the system tray area, the right mouse button click on the icon, and then through the interface "ADD Key" menu to import the private key generated by the second step, when you use Tortoisegit to operate the central server repository, you do not need to enter a user password.
5.4.2Git Server configuration Issues
Because Git is the author of Linux developing an open source version control software developed by Linus Torvalds to help manage the development of the Linux kernel, this software is based on the SSH protocol (note that secure Shell Protocol, not spring+ Struts+hibernate), so as long as the server is running SSH listener git central server can work, no additional configuration.
6. Summary
This article explains how to install and configure git on CentOS7 to become a central git server, and then demonstrates how Windows clients work with a git central server. It also involves two pits: one that does not change the git shell to Git-shell causes the operation times "Git did not exit cleanly (exit code 128)" Error, The other is the problem of using Tortoisegit to connect to the GIT central server without a password. As for Git's daily operations commands and processes, you can go to the online tutorials.

This article is from the "Zhou Gong (Zhou Jinchao) column" blog, please be sure to keep this source http://zhoufoxcn.blog.51cto.com/792419/1947244

Developers learn Linux (9): CentOS7 Compile and install Git-2.13.1 and use

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.