git本地提交自動部署到專案hooks

2021-09-03 01:16:04 字數 773 閱讀 7146

但我們在git提交到遠端**倉庫後,要想部署到線上還要到伺服器的發布目錄下git clone 或者git pull,以前我還自作聰明的寫了個指令碼,用於自動git pull,登入伺服器後直接執行./gitpull.sh就好,後來,直到後來,我發現原來可以有個更簡單的方法,那就是hooks,鉤子方法,它在你見的**倉庫的hoocks目錄下,(/var/opt/gitlab/git-data/repositories/zhangxiaoyuan/66xun.git/hooks)

cd hooks

vi post-receive

#!/bin/sh

unset git_dir

deploypath=/mnt/66xun/ #你自己發布**的目錄

git --work-tree=$deploypath checkout -f publish

chmod -r 777 $deploypath

cd $deploypath

git add . -a && git stash

git pull origin publish

退出儲存

chmod +x post-receive #賦予執行許可權

然後在你要發布的地方 git  clone 你的git庫 /root/helloworld --你要發布的**目錄(git clone /var/opt/gitlab/git-data/repositories/zhangxiaoyuan/66xun.git   把/mnt/66xun/66xun裡的.git放到/mnt/66xun

Git提交本地專案

我們向遠端倉庫提交專案有兩種情況,一種是遠端倉庫新建了專案,從本地轉殖下來後再我們的專案放到轉殖下來的資料夾中,但是這樣會多一層目錄 另一種情況就是直接將本地專案推到遠端倉庫,也就是遠端倉庫不要新建空的專案資料夾,第二種情況操作有點複雜 1.cd到本地專案資料夾下 2.git init 初始化 3....

提交乙個本地專案到git

touch readme.md 新建說明檔案 git init 在當前專案目錄中生成本地git管理,並建立乙個隱藏.git目錄 git add 新增當前目錄中的所有檔案到索引 git commit m first commit 提交到本地原始碼庫,並附加提交注釋 git remote add ori...

git 提交專案到github

前提是生成了ssh key 1 在本地建立乙個工作目錄 即資料夾 通過git init把它變成git倉庫 2 把專案複製到這個資料夾裡面,再通過git add 把專案新增到倉庫 3 再通過git commit m 注釋內容 把專案提交到倉庫 4 在github上設定好ssh金鑰後,新建乙個遠端倉庫,...