Home > Article > Development Tools > How to set up and configure a Git server
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
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
Configure environment variables
vim /etc/profile export PATH="$PATH:/usr/local/git/bin" source /etc/profile # 使修改立即生效
Server configuration
Create Git user
Create a git user group and user to run the git service:
groupadd git useradd git -g git
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
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"
After the above command is executed successfully, obtain the public key through the following command
cat ~/.ssh/id_rsa.pub
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/
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
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协议
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/
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 //推送到公共服务器
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/
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!