Setting Up a Git Server
In the previous chapter, we used Github for our remote repository. Public projects on Github are free, and since 2019, private repositories on Github can be used without any limits.
Of course, we can also set up our own Git server for private repository use.
Next, we will set up a Git server using Centos as an example.
1. Install Git
$ yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel perl-devel
$ yum install git
Next, we will create a git user group and user to run the git service:
$ groupadd git
$ useradd git -g git
2. Create Certificate Login
Collect the public keys of all users who need to log in. The public keys are located in the id_rsa.pub file. Import our public key into the /home/git/.ssh/authorized_keys file, one per line.
If the file does not exist, create it:
$ cd /home/git/
$ mkdir .ssh
$ chmod 755 .ssh
$ touch .ssh/authorized_keys
$ chmod 644 .ssh/authorized_keys
3. Initialize Git Repository
First, we select a directory to serve as the Git repository, let's say /home/gitrepo/tutorialpro.git. Enter the following commands in the /home/gitrepo directory:
$ cd /home
$ mkdir gitrepo
$ chown git:git gitrepo/
$ cd gitrepo
$ git init --bare tutorialpro.git
Initialized empty Git repository in /home/gitrepo/tutorialpro.git/
The above commands create an empty repository. Git repositories on the server typically end with .git. Then, change the ownership of the repository to the git user:
$ chown -R git:git tutorialpro.git
4. Clone Repository
$ git clone [email protected]:/home/gitrepo/tutorialpro.git
Cloning into 'tutorialpro'...
warning: You appear to have cloned an empty repository.
Checking connectivity... done.
Replace 192.168.45.4 with the IP address of your own Git server.
This completes the installation of our Git server.