Home > Development Tools > git > How to set up and configure a Git server

How to set up and configure a Git server

青灯夜游
Release: 2019-02-26 13:13:22
forward
5150 people have browsed it

The content of this article is to introduce how to build and configure a Git server. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

Install Git

Install dependencies

yum install curl-devel expat-devel gcc gcc-c++ 
yum install perl perl-devel gettext-devel openssl-devel zlib-devel
Copy after login

Compile and install Git

# 下载Git
wget https://www.kernel.org/pub/software/scm/git/git-2.9.5.tar.gz

# 解压
tar zxvf git-2.9.5.tar.gz
cd git-2.9.5

# 预编译、编译、安装
make configure
./configure --prefix=/usr/local/git
make && make install
Copy after login

Configure environment variables

vim /etc/profile
export PATH="$PATH:/usr/local/git/bin"
source /etc/profile # 使修改立即生效
Copy after login

Server configuration

Create Git user

Create a git user group and user to run the git service:

groupadd git
useradd git -g git
Copy after login

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. Put our public keys Import the keys into the /home/git/.ssh/authorized_keys file, one per line.

If there is no such file, you need to create it:

cd /home/git/
mkdir .ssh
chmod 755 .ssh
touch .ssh/authorized_keys
chmod 644 .ssh/authorized_keys
Copy after login

So how to generate the public key on your own client?

If it is a windows computer, you can open the Git client. If If you are using a Mac, you can open the terminal that comes with the Mac and execute the following command

ssh-keygen -t rsa -C "你的邮箱"  //例如ssh-keygen -t rsa -C "xxx@gmail.com"
Copy after login

After the above command is executed successfully, obtain the public key through the following command

cat ~/.ssh/id_rsa.pub
Copy after login

The terminal tool will print out the public key and copy it Public key, fill in the authorized_keys of the server

Initialize Git warehouse

First we select a directory as the Git warehouse, assuming it is/ home/gitrepo/blog, enter the command in the /home/gitrepo directory:

cd /home
mkdir gitrepo
chown git:git gitrepo/
cd gitrepo

git init --bare blog.git
# 执行完会有如下提示
Initialized empty Git repository in /home/gitrepo/blog.git/
Copy after login

The above command Git creates an empty warehouse. Git warehouses on the server usually end with .git. Then, change the user who owns the warehouse to git:

chown -R git:git blog.git
Copy after login

Clone the warehouse

git clone git@192.168.111.129:/home/gitrepo/blog.git
# 或
git clone ssh://git@192.168.111.129:22/home/gitrepo/blog.git  //版本库地址,支持ssh协议
Copy after login

Note: If it prompts git-upload here -pack: command not found, you can use the
command on the version server

ln -s /usr/local/git/bin/git-upload-pack /bin/
Copy after login

and then re-execute git clone
After successfully pulling the project, you can edit and submit it locally

touch index.php
git add index.php
git commit -a -m'提交index.php文件'
git push origin master   //推送到公共服务器
Copy after login

When executing the push command, if git-receive-pack: command not found error is reported, create a soft connection again

ln -s /usr/local/git/bin/git-receive-pack /bin/
Copy after login

Execute the push command again Can.

The above is the entire content of this article, I hope it will be helpful to everyone's study. For more exciting content, you can pay attention to the relevant tutorial columns of the PHP Chinese website! ! !

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

Related labels:
source:cnblogs.com
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