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:
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
In CentOS/RHEL system, run the following command:
sudo yum install git
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
Set a password for the new user:
sudo passwd git
Create a Git repository:
sudo mkdir /opt/git sudo chown git:git /opt/git
Initialize a Git repository:
cd /opt/git sudo -u git git init --bare new_repo.git
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.
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 ~/
Create SSH key:
ssh-keygen -t rsa -b 4096 -C "youremail@example.com"
Add the SSH key to the authorized_keys file:
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys chmod 600 ~/.ssh/authorized_keys
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
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!