English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Detailed Explanation of Setting Up a Git Server on Linux

Preface

GitHub is a free remote repository for hosting open source code. But for some commercial companies that view source code as life, they don't want to disclose the source code and are reluctant to pay GitHub for protection, they can only set up their own Git server as a private repository.

I plan to set up a git server myself. Although there are already very good git tools such as github, coding.net, etc., for security, to reduce restrictions and costs, it is better to have it on your own server. The following is the process of installation and configuration, welcome to discuss and communicate, I will reply in time.

Step 1

Install git: You can install it quickly through the command, the installation method for different Linux systems may vary, mine uses the yum method. Ubuntu can use apt-get command.

sudo yum install git 

Step 2

Add the git user, because the git server is only limited to project code exchange, it is better to open a dedicated user to access the git server for better management and control.

sudo adduser git 

Step 3

Set the login password for the git user. Because git provides ssh protocol login functionality, some have adopted the method of storing the client rsa_pub password to log in without a password. But I followed this method to store the public key file, modified the ssh configuration, changed the file permissions, and finally the actual test still did not work, and the password prompt still appeared when accessing git. So just set a password yourself, which is also safer. The workload is the same as that of the user sending the public key file to the administrator.

passwd git 

Step 4

Set the permissions for the git login user. To allow only git to be used when logging in remotely to git,-shell command, needs to be modified/etc/Find git:x: in the passwd file500:500:,,,:/home/git:/bin/Modify this line, usually at the last line, to git:x:500:500:,,,:/home/git:/usr/bin/git-shell Note: The numbers may be different according to the actual situation of your computer. After the above simple steps, the git environment has been set up.

The following is the fourth step of creating a git project: creating a repository. You can create it according to the existing project file directory. The method is to first enter the root directory of the project.

Then enter the following command

sudo git init 

Step 5

Modify the owner of the generated .git file to the git user

sudo chown -R git:git .git 

Step 6

The above only creates an empty repository, and you need to add the project files into it. The following commands are common git operation commands, which belong to the usage methods of git. Those who are interested can learn the relevant commands themselves.

git add . 
git commit -a -m "init a git project " 

After the above steps, the git project repository on the server side has been established. Others can clone the project files of the git server to the local. However, you need to install git on your client first.-shell tool. For those who have installed the GitHub client, it is very easy to set up git in its Git Shell terminal.

git clone <a target=_blank href="mailto:git@host-IP:/your-git-repository">git@host-IP:/your-git-repository</a> 

Summary

In fact, setting up a Git server is very simple, usually10It can be completed in one minute. That's all the content of this article. I hope the content of this article can bring a certain amount of help to everyone's study or work.

Declaration: The content of this article is from the Internet, and the copyright belongs to the original author. The content is contributed and uploaded by Internet users spontaneously. This website does not own the copyright, has not been edited by humans, and does not assume any relevant legal liability. If you find any content suspected of copyright infringement, please send an email to: notice#oldtoolbag.com (Please replace # with @ when sending an email to report violations, and provide relevant evidence. Once verified, this site will immediately delete the content suspected of infringement.)

You May Also Like