伺服器上搭建git倉庫與鉤子hook的配置

2021-07-25 12:03:28 字數 3071 閱讀 8715

本伺服器是基於阿里雲上的伺服器,伺服器上的web服務在/wwwroot/www目錄下

ssh root/使用者名稱@伺服器位址,進入伺服器

cd /home/git/ #進入git目錄

git init --bare huang.git #初始化乙個git倉庫

需要先在伺服器上新增個git使用者組,並在git使用者組裡新增個git使用者,後面的操作都是使用git這個使用者身份操作的。因為我是root許可權登入的,所以是root許可權,這處必須要修改的。

chown -r git:git huang.git/
此時,git目錄下的huang.git資料夾git使用者組修改完畢,接下來是修改hook,此處不詳述鉤子的作用,這裡只說明如何用,詳細可以自己去查詢了解。

進入剛建立的huang.git資料夾裡的hooks資料夾中,裡面有post-receive和post-update這兩個檔案(如果沒有的話需要自己新建)

下面是配置好的post-receive裡的檔案內容:

#!/bin/sh  

# # an example hook script for the "post-receive" event.

# # the "post-receive" script is run after receive-pack has accepted a pack

# and the repository has been updated. it is passed arguments in through

# stdin in the form

# # for example:

# aa453216d1b3e49e7f6f98441fa56946ddcd6a20 68f7abf4e6f922807889f52bc043ecd31b79f814 refs/heads/master

# # see contrib/hooks/ for a sample, or uncomment the next line and

# rename the file to "post-receive".

#. /usr/share/git-core/contrib/hooks/post-receive-email

# cd /wwwroot/www/你的專案檔名(這裡為huang)

cd /wwwroot/www/huang

env -i git pull

下面是配置好的post-update裡的檔案內容:

#!/bin/sh  

# # an example hook script for the "post-receive" event.

# # the "post-receive" script is run after receive-pack has accepted a pack

# and the repository has been updated. it is passed arguments in through

# stdin in the form

# # for example:

# aa453216d1b3e49e7f6f98441fa56946ddcd6a20 68f7abf4e6f922807889f52bc043ecd31b79f814 refs/heads/master

# # see contrib/hooks/ for a sample, or uncomment the next line and

# rename the file to "post-receive".

#. /usr/share/git-core/contrib/hooks/post-receive-email

cd /wwwroot/www/huang

env -i git pull

git目錄下的檔案配置完畢,接下來進入web目錄/wwwroot/www。將git目錄下剛建立的空倉庫的內容clone過來,命令如下:

chown -r git:git huang/
到此,伺服器上的倉庫檔案配置完畢。在本地clone遠端伺服器上的空倉庫,命令如下:

git clone git@伺服器位址:huang.git
進入該專案資料夾,新增**檔案

這個時候git目錄下的**會得到更新,同時由於鉤子的作用,web目錄(/wwwroot/www)下的**也得到了同步更新。如果web目錄下的**沒有更新,可能是版本產生衝突了,可以在web目錄下的專案資料夾(/wwwroot/www/huang)下git pull一下,這樣**就可以正常維護了。

注意,出現如下問題時:

remote: error: insufficient permission for adding an object

to repository database ./objects

remote: fatal: failed to write object

error: unpack failed: unpack-objects abnormal exit

客戶端機器對伺服器git**倉庫的寫許可權出了問題。改變**倉庫下,所有檔案的訪問許可權,同組可寫,確認嚴格按照上面的指令執行。chown -r *

linux伺服器上搭建git倉庫

建立git使用者,使用者組預設為git useradd git 修改git賬戶的密碼 passwd gityum install y git 切換至 資料夾 cd home git code 例項化倉庫 git init bare search.git 修改許可權 chown r git git s...

在伺服器上搭建遠端git倉庫

推薦使用執行liunx的機器 請獲取root許可權後進行下面操作 檢查是否安裝了git如果有版本號就無需再安裝 git v 安裝git sudo apt get install gitsudo adduser git收集所有需要登入的使用者的公鑰,就是他們自己的id rsa.pub檔案按照本文找id...

git鉤子放伺服器 git伺服器自動鉤子

實現自動同步到站點目錄 www 就比如剛才我們往遠端倉庫推送了index.php檔案,雖然提示推送成功,但是我們現在在伺服器端還看不到效果,心理總是不爽。又比如我寫了個html頁面,我想在站點中馬上看到,那自動同步就派上用場了。自動同步功能用到的是 git 的鉤子功能,伺服器端 進入裸倉庫 home...