To set up Git server, you need to prepare a machine running Linux. I used CentOS here. The installation steps are as follows:

1. Use Xshell to connect to the cloud server

Git 1.8.3 has been installed. The default git version installed by yum is not the latest version, as described below.

yum -y install curl curl-devel zlib-devel openssl-devel perl cpio expat-devel gettext-devel gcc cc perl-ExtUtils-MakeMaker
Copy the code

Wait patiently for the installation and enter Y when prompted. The installation of the service environment is completed as shown in the picture below:

After the installation, you can view the installed Git version as follows:

It’s really easy to install with Yum, but one of the problems with Yum is that the installed version is not easy to control. As shown in the image above, the installed version is 1.8.3, which is too old.

The loginGithub Git release interface, you can see that the latest version is 2.26.0, as shown below:

If you need to install the latest version of Git, download the latest source code from Github, compile it, and install it.

Install git:

  • Get lot wanted to download git installation download links, here I choose v. 2.25.0 version of the Linux server, download, command is: the wget HTTP: / / https://github.com/git/git/archive/v2.25.0.tar.gz

  • To decompress the package, run the tar -zxvf v2.25.0.tar.gz command

  • When installing the dependencies required for compiling source code in Step 2, yum automatically installed Git. You need to uninstall the old version of Git by running the following command: yum remove Git

  • However, after downloading the package and decompressing the file, the following error occurs:The error occurred because the command was passedWget HTTP: / / https://github.com/git/git/archive/v2.25.0.tar.gzThe downloaded installation package is not complete, there is an error in decompressing, you can passGit version of GithubDownload the installation package to a local PC, run commands to upload the local installation package to the server, and decompress the installation package.

  • Local file is uploaded to the server using the commandyum install lrzszInstall LRZSZ on the server and enterrzThe following dialog box will be displayed to select upload

    You can also download files by sZ + file name.

  • After the local installation package is uploaded, run theThe tar - ZXVF git - 2.25.0. Tar. GzUnpack the

    Decompression command in the ZXVF v can not be added, v is to show the progress of the meaning.

  • After decompressing the source code, go to CD git-2.25.0, which contains the source code, and compile the source code. You need to generate a Makefile, but there is no Makefile in the source code. To generate a Makefile, run the autoconf command, and then run the./configure command. This will generate a Makefile, and C requires a Makefile. This compilation takes about a minute, and when it’s finished, you install it by running make install, which will install Git into the appropriate directory

  • However, an error is reported when the autoconf command is executed

  • First check your installation package yum WhatProvides autoconf AutomakeThen run the following command in the root directory:Yum -y install autoconf - 2.69-11. El7. NoarchandYum -y install automake - 1.13.4-3. El7. Noarch

  • Then go back to git-2.25.0 and execute itautoconfCommand, and then execute./configureCommand, and then executemakeCommand compile, compile is completed after installation, executemake installCommand to install Git, which will install it in the appropriate directory

4. Create an account to upload and download files using git remote repository

adduser -r -c 'git version control' -d /home/git -m git

After this command is executed, the /home/git directory is created as the home directory of the git user (the user name ends with this command).

5. Set a password:

The command is passwd git

Now look at the folder with git users under /home. Git is already created

Now we can go throughsu gitCommand to switch to git user and passwhoamiCommand to view the current user. You can view the current user named git

Run the CD ~ command to go to git’s home and print the current path through PWD

Git git git git git git git git git git git git git git gitgit initInitialization is the default working directory of the repository, but listed on the server to create a pure repository (without working directory), so when using the command git init — bare, initialize the repository is so pure repository, without working directory on the server of the warehouse basic it is without a working directory pure version of the library, the following figure

Now that the local repository on the server is initialized, we can use the repository as a remote repository and push the code from the local repository to the remote repository on the server.