見出し画像

2020-05-09(土) GitのTriangular Workflowという名前を覚えた

Triangular Workflowという名前を覚えた。例えばGitHubで何かのリポジトリ(UPSTREAM)をFork(ORIGIN)しさらに手元にclone(LOCAL)すると、自分から見えているリポジトリはUPSTREAM,ORIGIN ,LOCALの3つ存在する。この3つのリポジトリを協調させて開発するのがTraiangular Workflowと呼ばれるようだ。

この方法を使うと、UPSTREAM の master のコミットが更新されたとき、それを LOCAL のブランチに取り込む作業を git pull で行える。この方法を使わないときに git fetch upstream master && git rebase upstream/master と書くのと同じかなあ。そして git push すると ORIGIN のリポジトリに push できる。

この Workflow を使うために設定する git config は 2 つ remote.pushdefaultpush.default だ。

remote.pushdefault は

The remote to push to by default. Overrides branch.<name>.remote for all branches, and is overridden by branch.<name>.pushRemote for specific branches.

とあるから、何も指定しないときどのリポジトリへ push するかという設定かな。これを origin に指定する。LOCAL リポジトリからの push 先は常に ORIGIN リポジトリだから妥当だ。

push.default は

Defines the action git push should take if no refspec is given (whether from the command-line, config, or elsewhere). Different values are well-suited for specific workflows; for instance, in a purely central workflow (i.e. the fetch source is equal to the push destination), upstream is probably what you want.

とあるから、何も指定しないときどのリポジトリのブランチへ push するかという設定かな。これを current に指定する。current は

current - push the current branch to update a branch with the same name on the receiving end. Works in both central and non-central workflows.

LOCAL リポジトリのブランチ名を、push 先リポジトリのブランチ名として push するという設定のようだ。

全ての変更は UPSTREAM リポジトリからやってくる、手元の LOCAL リポジトリでは UPSTREAM からの差分をとって開発する、変更を UPSTREAM にとりこんでもらうための Pull Request を作るために LOCAL リポジトリにある変更を ORIGIN リポジトリに push する。という UPSTREAM -> LOCAL -> ORIGIN -> (Pul lRequest) の形はよくある OSS 開発の形にマッチしている。k便利そうなので設定して使ってみることにする。

ヘッダ画像は https://github.blog/2015-07-29-git-2-5-including-multiple-worktrees-and-triangular-workflows/#improved-support-for-triangular-workflows から拝借した。

この記事が気に入ったらサポートをしてみませんか?