search
HomeDevelopment ToolsgitHow 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!

Statement
This article is reproduced at:博客园. If there is any infringement, please contact admin@php.cn delete
Git and GitHub: Exploring Their Roles and FunctionsGit and GitHub: Exploring Their Roles and FunctionsMay 09, 2025 am 12:25 AM

The role and function of Git and GitHub in software development is to manage code and collaborative development. Git efficiently manages code versions through commit, branch and merge functions, while GitHub provides code hosting and collaboration tools such as PullRequest and Issues to improve team collaboration efficiency.

GitHub: Discovering, Sharing, and Contributing to CodeGitHub: Discovering, Sharing, and Contributing to CodeMay 08, 2025 am 12:26 AM

GitHub is the preferred platform for developers to discover, share and contribute code. 1) Find specific code bases through search functions, such as Python projects. 2) Create a repository and push code to share with developers around the world. 3) Participate in open source projects and contribute code through Fork and PullRequest.

Using Git with GitHub: A Practical GuideUsing Git with GitHub: A Practical GuideMay 07, 2025 am 12:11 AM

Git is a version control system, and GitHub is an online platform based on Git. The steps to using Git and GitHub for code management and team collaboration include: 1. Initialize the Git repository: gitinit. 2. Add files to the temporary storage area: gitadd. 3. Submit changes: gitcommit-m"Initialcommit". 4. Related to the GitHub repository: gitremoteaddoriginhttps://github.com/username/repository.git. 5. Push code to GitHub: gitpush-uoriginmaste

GitHub's Impact: Software Development and CollaborationGitHub's Impact: Software Development and CollaborationMay 06, 2025 am 12:09 AM

GitHub has a far-reaching impact on software development and collaboration: 1. It is based on Git's distributed version control system, which improves code security and development flexibility; 2. Through functions such as PullRequest, it improves team collaboration efficiency and knowledge sharing; 3. Tools such as GitHubActions help optimize the development process and improve code quality.

Using GitHub: Sharing, Managing, and Contributing to CodeUsing GitHub: Sharing, Managing, and Contributing to CodeMay 05, 2025 am 12:12 AM

The methods of sharing, managing and contributing code on GitHub include: 1. Create a repository and push code, and write README and LICENSE files; 2. Use branches, tags and merge requests to manage code; 3. Fork the repository, modify and submit PullRequest contribution code. Through these steps, developers can effectively use GitHub to improve development efficiency and collaboration capabilities.

Git vs. GitHub: A Comparative AnalysisGit vs. GitHub: A Comparative AnalysisMay 04, 2025 am 12:07 AM

Git is a distributed version control system, and GitHub is a Git-based collaboration platform. Git is used for version control and code management, while GitHub provides additional collaboration features such as code review and project management.

Git vs. GitHub: Understanding the DifferenceGit vs. GitHub: Understanding the DifferenceMay 03, 2025 am 12:08 AM

Git is a distributed version control system, and GitHub is an online platform based on Git. Git is used for version control, branch management and merger, and GitHub provides code hosting, collaboration tools and social networking capabilities.

GitHub: The Frontend, Git: The BackendGitHub: The Frontend, Git: The BackendMay 02, 2025 am 12:16 AM

Git is a back-end version control system, and GitHub is a front-end collaboration platform based on Git. Git manages code version, GitHub provides user interface and collaboration tools, and the two work together to improve development efficiency.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),