簡體   English   中英

生產,登台,開發網站和git repos在同一台服務器上:如何設置GIT_DIR和GIT_WORK_TREE

[英]Production, Staging, Dev websites and git repos on same server: how to setup GIT_DIR and GIT_WORK_TREE

我已經閱讀了很多帖子,這些帖子似乎讓我很接近,但並不是我想要的。 我有一台服務器。 在它上面,我有3個網站:www.domain.com,staging.domain.com和dev.domain.com。 我也在local.domain.com上開發,並使用Gi​​tHub作為我的核心倉庫。

我想把我的git存儲庫從我的網絡根源中刪除。 我願意這樣做。 我正在嘗試的是:

/home/user/git/production.git 
/home/user/git/staging.git
/home/user/git/development.git

我知道如果通過設置GIT_DIR和GIT_WORK_TREE(我在.bash_profile中導出路徑)只有1個站點和repo,如何做到這一點。

我似乎可以在每個存儲庫的config設置工作樹,例如:

[core]
    bare = false
    worktree = /home/user/domains/www.domain.com/public_html

但是我該如何設置GIT_DIR

因此,如果我在/ home / user / domains / www .domain.com / public_html並執行git status等,則它指的是生產 git repo。 如果我在/ home / user / domains / staging .domain.com / public_html中,則它與staging .git綁定。

您可以使用gitlink文件而不是設置$GIT_DIR 要做到這一點,只需進入每個工作樹的根目錄並運行:

echo "gitdir: /home/user/git/production.git" > .git

這會在您的Web根.git中生成一個.git文件,但如果有人訪問該文件,那么唯一會泄漏的就是存儲庫的路徑。 這將避免需要根據您所在的目錄設置$GIT_DIR變量來玩游戲。

你想做什么?

/home/user/git/production.git它應該檢測工作目錄為/home/user/domains/www.domain.com/public.html並且push / pull / checkout應該在那里正常工作。 不幸的是,git不是通靈的 - 來自沒有.git文件夾的隨機目錄git甚至不知道在哪里查找配置文件(沒有“gitdir”文件 ,正如我剛從其他答案中了解到的那樣)。

你總是可以傳入git --git-dir=~git/production.git checkout ...等等,但我敢打賭你正在尋找一種自動解決方案。

也許嘗試在shell腳本中包裝git? 如果你把它作為~/bin/autogit

#!/bin/bash
DIR=$(pwd)
if (fgrep -q domains/www.domain.com <<< "$DIR"); then
  git --git-dir=/home/user/git/production.git $@
elif (fgrep -q domains/staging.domain.com <<< "$DIR"); then
  git --git-dir=/home/user/git/staging.git $@
elif (fgrep -q domains/local.domain.com <<< "$DIR"); then
  git --git-dir=/home/user/git/development.git $@
fi
echo "Autogit failed from directory $DIR."
exit 1      

(旁注:為什么你有三個repos?我發現有一個帶有三個不同分支名稱的repo,以及一個將每個分支檢出到其相應目錄的腳本更常見。)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM