1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

OSSを社内で使うときのミラー運用

Posted at

概要

ちょっとした備忘録です。
OSSのリポジトリをforkはしたくないけど、社内リポジトリで運用していきたい時に役立つ内容となります。

OSSのライセンスは要確認。GPLとか…

この手順が向いているケース

  • 社内/プライベート用に改変する
  • でもoriginalの更新を受け入れたい

想定する構成

  • upstream: OSS 公式リポジトリ
  • origin: 社内 GitHub / GitLab のミラーリポジトリ
  • local(sync): 初回・定期同期用の作業ディレクトリ
  • local(dev): 開発者が使う通常の clone
upstream (OSS公式)
↑ fetch
local(sync)
↓ push --mirror
origin (社内ミラー)
↓ clone
local(dev)

1. 空のミラーリポジトリを作成する

まず GitHub / GitLab に 空のリポジトリ を作成します。

  • README は作らない
  • 初期コミットなし

例として、リポジトリは以下のようにします。
(リポジトリ名を一致させる必要はないです)
git@github.com:your-company/awesome-oss.git

2. OSS を mirror clone する

通常の clone ではなく、--mirror を使います。

git clone --mirror https://github.com/example/awesome-oss.git
cd awesome-oss.git

この時点で、

  • 全ブランチ
  • 全タグ
  • refs / notes
  • 削除済みブランチ情報

がすべて含まれます。

3. 社内/プライベートリポジトリへ push する

先ほど作成した空のリポジトリにpushします。

git push --mirror git@github.com:your-company/awesome-oss.git

これで OSSオリジナル と 完全に同一な状態のミラーが作成されます。

4. upstream の更新を取り込む(定期運用)

クローンしたプライベートのリポジトリlocal(sync)でupstreamとしてOSSのリポジトリを追加します。

git remote add upstream https://github.com/example/awesome-oss.git

確認

git remote -v
# 出力例
origin    git@github.com:your-company/awesome-oss.git (fetch)
origin    git@github.com:your-company/awesome-oss.git (push)
upstream  https://github.com/example/awesome-oss.git (fetch)
upstream  https://github.com/example/awesome-oss.git (push)

この構成だと、

origin = 社内の正
upstream = OSS 公式

と整理しやすいです。

最後に

git fetch upstream
git checkout main
git merge upstream/main
git push origin main

を叩いて社内/プライベートのリポジトリにマージ

更新取り込む時は上記4つのコマンドを叩く運用になります。

注意点

個人的には、
「このリポジトリは同期専用」という意識を持つのが一番大事だと感じています。
upstreamに間違えてpushしてしまうのは危険ですので…

まとめ

  • 初回は完全ミラーを作り、その後は必要に応じて社内側で改変しつつ upstream を取り込む
  • 更新は git fetch upstream && git merge upstream/main
  • 開発用途と取り込みディレクトリは分離するのが安全

社内で OSS を長く安定して使うための、
ひとつのベース運用として参考になれば嬉しいです。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?