Home > Development Tools > git > body text

How to quickly set up a Git server on liunx (tutorial)

PHPz
Release: 2023-04-26 09:55:44
Original
1308 people have browsed it

In today's software development industry, version control is an important part that cannot be ignored. Git is one of the most popular version control systems currently available. Its powerful functions and easy-to-use interface make many developers choose to use Git for project management and collaboration. In this article, we will provide you with a Git server installation tutorial to help you quickly set up a Git server in a Linux system.

Before installing the Git server, we need to ensure that the system has the necessary dependencies installed. These dependencies include:

  1. Git client
  2. SSH client and server
  3. If you use the HTTPS protocol to connect to Git, you need to install a web server such as Apache or Nginx
  4. Install Git Server

To install Git server, we can use the package manager to download and install.

  • In Debian/Ubuntu system, run the following command:

    sudo apt-get update
    sudo apt-get install git-core
    Copy after login
  • In CentOS/RHEL system, run the following command:

    sudo yum install git
    Copy after login
  1. Configuring Git Server

Once the Git server is installed, we need to create a Git user to manage the Git repository.

  • Create a new Git user:

    sudo adduser git
    Copy after login
  • Set a password for the new user:

    sudo passwd git
    Copy after login
  • Create a Git repository:

    sudo mkdir /opt/git
    sudo chown git:git /opt/git
    Copy after login
  • Initialize a Git repository:

    cd /opt/git
    sudo -u git git init --bare new_repo.git
    Copy after login

    Here we choose to create a file named new_repo.git in the /opt/git directory of bare warehouse. A bare repository is a type of Git repository that does not include a working directory. It only contains version history and metadata from the Git repository.

  1. Configure SSH service

SSH is the most widely used protocol in Git projects because it can provide a secure and encrypted connection. To configure the SSH service, we need to create an SSH key on the server and add it to the authorized_keys file of the newly created Git user.

  • Switch to the home directory under the Git user:

    su - git
    cd ~/
    Copy after login
  • Create SSH key:

    ssh-keygen -t rsa -b 4096 -C "youremail@example.com"
    Copy after login
  • Add the SSH key to the authorized_keys file:

    cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
    chmod 600 ~/.ssh/authorized_keys
    Copy after login
  1. Test the Git server

Now the Git server is ready and we can use Git client to test if it works properly. Assuming you are using a Git client on another computer, then you can execute the following command to connect to the Git server you just created:

git clone git@yourservername:/opt/git/new_repo.git
Copy after login

This will clone the new_repo.git repository to the local computer and remotely Create a new branch on the Git server.

In this article, we provide a Git server installation tutorial to help you easily create your own Git server on a Linux system. After installing and configuring the Git server, you can use SSH protocol, HTTPS protocol, or other protocols to access your Git repository. I wish you a happy use!

The above is the detailed content of How to quickly set up a Git server on liunx (tutorial). For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!