• 请不要在回答技术问题时复制粘贴 AI 生成的内容
MasterCai
V2EX  ›  程序员

自建 git 服务器能否连接 github

  •  
  •   MasterCai · Apr 25, 2023 · 6307 views
    This topic created in 1292 days ago, the information mentioned may be changed or developed.

    问题是这样的:在一个局域网内有多台设备,我想在局域网内自建一个 git 服务器(这个用什么都无所谓),用于在局域网内统一同步和管理这些设备上的代码,这个很好实现。

    但是能不能让这个 git 服务器和 github 相连接,可以定期同步代码上去呢?

    目前用 gitlab 搭了一个,本地功能正常,但是无法上传 github ,有没有什么解决方案?(不用 gitlab 也可以)

    图片可能表达的更清晰一点:

    https://imgur.com/a/9PhyGxC

    Supplement 1  ·  Apr 26, 2023
    gitlab 和 gitea 都尝试了一下,目前使用的是 gitea ,主要是因为:
    1. gitlab 内存占用太大,刚装起来就 7g ,不知道是不是因为通过 docker 安装的原因
    2. gitlab ce 版只能 push
    3. gitlab 功能太强,个人使用有点冗余

    现在是用 gitea 先从 github 上镜像一个仓库过来,然后再给它添加一个 push 设置,想实现双向自动同步,试用一段时间看看会不会出现冲突。
    29 replies  •  2023-04-26 22:39:54 +08:00
    shunia
    shunia
    Apr 25, 2023❤️1
    1
    gitea ,可设置自动同步至所有公共代码平台
    0o0O0o0O0o
    0o0O0o0O0o
    Apr 25, 2023 via iPhone
    2
    你可以通过 git remote set-url --add origin <github> 来同时额外 push 到 Github
    IvanLi127
    IvanLi127
    Apr 25, 2023 via Android
    3
    可以,楼上说得对,我现在就是本地 gitea ,定期推代码到 github 上。
    MasterCai
    MasterCai
    OP
    Apr 25, 2023 via iPhone
    4
    @shunia 感谢,这个还真没了解过,去看一下
    @IvanLi127 感谢

    @0o0O0o0O0o 这个我知道,就是想用一个服务器集中管理
    debuggerx
    debuggerx
    Apr 25, 2023 via Android
    5
    gitlab 有设置镜像的选项 所有提交都可以自动镜像到 gh
    Scirocco
    Scirocco
    Apr 26, 2023
    6
    @debuggerx 这个好像是 EE 版本,免费的 CE 版不行
    tinyint00
    tinyint00
    Apr 26, 2023❤️1
    7
    - 每个仓库建立一个脚本分支
    - 起一个服务用于定时调用
    - 服务定时 `rebase` 你需要同步的分支
    - 服务定时 推送 `rebase` 过来的分支到指定 git 平台

    本质上就是一个定时脚本能够解决。
    或者更极端点,用钩子去触发你的脚本。配置远程平台当成镜像
    skiy
    skiy
    Apr 26, 2023 via iPhone
    8
    gitlab 仓库中的镜像设置可以设置“推”或“拉”
    NouveauNom
    NouveauNom
    Apr 26, 2023
    9
    7L 说的对。用脚本。
    datadump
    datadump
    PRO
    Apr 26, 2023❤️2
    10
    脚本来了

    git clone --bare http:*//....(原始仓库地址)*

    cd project.git ( project 即为你的项目名称)

    git push --mirror http:*//...(目标仓库地址)*
    Sum0l
    Sum0l
    Apr 26, 2023
    11
    楼上的脚本言简意赅,甚为实用
    artnowben
    artnowben
    Apr 26, 2023
    12
    不如直接用 github ,或者 gitlab 吧;简单一点,让生活轻松一点。
    debuggerx
    debuggerx
    Apr 26, 2023
    13
    @Scirocco https://docs.gitlab.com/ee/user/project/repository/mirror/push.html#set-up-a-push-mirror-from-gitlab-to-github

    我是直接用 pve 的 CT 模板装的 gitlab-ce ,这个功能一直好用的
    MasterCai
    MasterCai
    OP
    Apr 26, 2023
    14
    @debuggerx
    @skiy ce 版本只能 push

    @tinyint00
    @wjx0912 这个方法有意思,学到了
    debuggerx
    debuggerx
    Apr 26, 2023
    15
    @MasterCai 所以你需要的是 gitlab 定期同步来自 github 的提交?双向同步?

    如果是主用 gitlab ,github 只做备份用,测的 push mirror 完全就够了啊
    Scirocco
    Scirocco
    Apr 26, 2023
    16
    @debuggerx 记错了记错了,确实是可以 push 的
    pota
    pota
    Apr 26, 2023
    17
    之前是 gitea 配和 drone CI 自动同步的,现在发现 gitea 自带了😂 方便了很多
    28Sv0ngQfIE7Yloe
    28Sv0ngQfIE7Yloe
    Apr 26, 2023
    18
    如果不想引入其他依赖,还是定时脚本来的简单
    MasterCai
    MasterCai
    OP
    Apr 26, 2023
    19
    @debuggerx 是想实现双向同步,但是好像不行;目前用 gitlab 确实挺好的,但是内存占用太大了
    debuggerx
    debuggerx
    Apr 26, 2023
    20
    @MasterCai gitlab 到 github 就是 mirror push 功能,github 到 gitlab 就用 action ,比如 https://github.com/pixta-dev/repository-mirroring-action

    这样不就双向同步了
    MasterCai
    MasterCai
    OP
    Apr 26, 2023
    21
    @debuggerx 还可以这样,不过主要原因是 gitlab 太大了。。所以目前在用轻量的 gitea
    documentzhangx66
    documentzhangx66
    Apr 26, 2023
    22
    为何不试试 gitlab ee 的 docker ?

    https://docs.gitlab.com/ee/install/docker.html
    documentzhangx66
    documentzhangx66
    Apr 26, 2023
    23
    @MasterCai

    gitlab ee 的 docker 镜像, 不压缩 3G ,zstd 压缩后 1.3G ,大吗?
    BurYiA
    BurYiA
    Apr 26, 2023
    24
    用 ci 功能去做?( github 的 Actions )
    每个项目写个配置,push 的时候自动同步到 github (说白了也是自动执行脚本)

    轻量的 git 可以看看 OneDev ,基本功能都有,可 docker 搭建
    MasterCai
    MasterCai
    OP
    Apr 26, 2023
    25
    @documentzhangx66 gitlab ee 不是收费嘛

    @BurYiA 明白了
    documentzhangx66
    documentzhangx66
    Apr 26, 2023
    26
    @MasterCai

    说是收费,但你先试试再说,反正 docker 版,试错没成本。
    LindsayZhou
    LindsayZhou
    Apr 26, 2023❤️1
    27
    看起没人说。
    我自己的仓库的话,会自己加服务端的 post-receive 钩子脚本: https://git-scm.com/docs/githooks
    有上传的时候自动触发同步到 github

    我是手工管理 bare 仓库,走 ssh 上传,加 cgit 和 git-daemon 公开分享。
    这种方式非常轻量,写 hooks 也很方便。
    我最近还在 hooks 里,用 systemd-run 和 go-task 简单做了一个通用的 CI 。

    不想自己管理 bare 仓库的话,也有 Gitosis Gitolite 之类的东西,我没用过就不多说了。
    LindsayZhou
    LindsayZhou
    Apr 26, 2023❤️1
    28
    @LindsayZhou #27
    说起来,前阵子有简单试过这个: https://github.com/charmbracelet/soft-serve
    挺漂亮的,也许可以看看。
    MasterCai
    MasterCai
    OP
    Apr 26, 2023 via iPhone
    29
    现在发现问题了,gitea 好像不能同时设置 push 和 pull ,对于镜像迁移来的仓库无法进行 push 。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1559 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 54ms · UTC 07:37 · PVG 15:37 · LAX 23:37 · JFK 02:37
    ♥ Do have faith in what you're doing.