繁体   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