安裝Git
1、更新系統(tǒng)軟件包
sudo yum update y
2、安裝Git
sudo yum install git y
3、檢查Git版本
git version
創(chuàng)建Git用戶
1、創(chuàng)建新用戶并設置密碼
sudo adduser git sudo passwd git
2、將新用戶添加到sudo組,以便具有管理員權限
sudo usermod aG sudo git
配置Git用戶
1、切換到新創(chuàng)建的git用戶
su git
2、生成SSH密鑰對
sshkeygen t rsa C "your_email@example.com"
3、將公鑰復制到服務器的~/.ssh/authorized_keys
文件中
cat ~/.ssh/id_rsa.pub | pbcopy
4、測試SSH連接是否成功
ssh T git@localhost
創(chuàng)建Git倉庫
1、在服務器上創(chuàng)建一個空目錄作為Git倉庫的根目錄,/var/www/html/myrepo.git
mkdir /var/www/html/myrepo.git && cd /var/www/html/myrepo.git && git init bare shared=group
2、設置目錄權限,使得其他用戶可以訪問和推送更改到該倉庫,請將your_username
替換為實際的用戶名。
chown R your_username:your_username myrepo.git && chmod R g+rwX myrepo.git && chmod R orwx myrepo.git && chmod +x hooks/* && chmod +x postupdate && chmod +x postreceive && chmod +x updateserverinfo && chmod +x prereceive && chmod +x preparecommitmsg && chmod +x receivepack && chmod +x updateindex && chmod +x indexpack && chmod +x preautogc && chmod +x autogc && chmod +x postcheckout && chmod +x postmerge && chmod +x prerebase && chmod +x rebase && chmod +x postrewrite && chmod +x updaterefs && chmod +x sendpack && chmod +x pushtocheckout && chmod +x receivepackperl && chmod +x servegitshell && chmod +x daemonexportall && chmod +x daemonstatus && chmod +x daemonstart && chmod +x daemonstop && chmod +x help2man && chmod +x incominghook && chmod +x logcommand && chmod +x procpsuser && chmod +x receivepack || true && chown R your_username:your_username myrepo.git || true && find myrepo.git type d exec chmod u+rwx {} ; || true && find myrepo.git type f exec chmod u+rw {} ; || true && find myrepo.git type f exec touch {} ; || true || true || true || true || true || true || true || true || true || true || true || true || true || true || true || true || true || true || true || true || true || true || true || true || true || true || true || true || true || true || true || true || true || true || true || true || true || true || true || true || true || true || true || true || true || true || true || true || true || true || true || true || true || true || true || true || true || true || true || true || true || true || true || true || true || true || true || true || true || true || true || true || true || true || true || true || true || true || true || true || true || true || false
客戶端克隆倉庫并推送更改
1、在客戶端計算機上克隆遠程倉庫到本地文件夾,/Users/your_username/myrepo
,請將your_username
替換為實際的用戶名。
git clone git@localhost:/var/www/html/myrepo.git /Users/your_username/myrepo
2、在客戶端計算機上添加文件并提交更改,創(chuàng)建一個名為README.md
的文件。
echo "Hello, World!" > README.md && git add README.md && git commit m "Add README" && git push origin master
下面是一個簡化的步驟介紹,指導如何在CentOS系統(tǒng)上搭建Git服務器:
yum install y git
adduser git
git init bare /data/git/learngit.git
chown git:git /data/git/learngit.git
git clone git@:/data/git/learngit.git
yes
確認請注意,上述介紹是基于提供的信息摘要制作的,實際操作中可能需要考慮額外的安全設置和權限管理,對于生產(chǎn)環(huán)境,建議詳細規(guī)劃服務器配置,包括但不限于用戶權限控制、倉庫備份、日志管理等,如果選擇使用SSH密鑰進行認證,應當生成并分發(fā)SSH密鑰,并在服務器上配置好相應的權限,確保安全性。