# What is "Github Flow" Gitによるプログラム開発のBest practiceである[Git-flow](https://nvie.com/posts/a-successful-git-branching-model/) を改良したもの。 複雑すぎる点、GitCUI頼みな点などが導入しづらいと言われている。一方で、リリース管理が必要な場合には有効。 参考:http://www.atmarkit.co.jp/ait/articles/1708/01/news015.html そこで、GitHubは、自身のProductであるGitHubの利用を前提に、よりWorkflowをシンプルにした開発フローを作った。それが「GitHub Flow」。 ## How to 前提として、masterブランチを「常にデプロイ可能なプロダクトのマスター」と捉える。Dev-Ops向き。 ### 準備 1. GitHub上でチームのリポジトリを、自分のアカウントにフォークする(ここはチームによっては省略可能) 2. `git clone https://github.com/MyTeam/product.git` する 3. `git remote set-url origin https://github.com/yourname/product.git` 自分のローカルリポジトリのoriginを、GitHubの自分のリポジトリ(先程フォークしたリポジトリ)に設定する 4. `git remote add upstream https://github.com/MyTeam/product.git` 自分のローカルリポジトリに、新たにupstreamとしてチームのリポジトリを設定する これで上流(upstream)と自分(origin)のそれぞれのリモートがある状態になる 5. `git remote add pr https://github.com/MyTeam/product.git` `git config remote.pr.fetch '+refs/pull/*:refs/remotes/pr/*'` Pull Request(PR)取得用コマンドとして`fetch`を設定している。 確認してみましょう。 ``` $ git remote -v origin ssh://git@github.com/yourname/product.git (fetch) origin ssh://git@github.com/yourname/product.git (push) pr ssh://git@github.com/MyTeam/product (fetch) pr ssh://git@github.com/MyTeam/product (push) upstream ssh://git@github.com/MyTeam/product (fetch) upstream ssh://git@github.com/MyTeam/product (push) ``` ``` $ git config --list remote.origin.url=https://github.com/yourname/product.git remote.origin.fetch=+refs/heads/*:refs/remotes/origin/* remote.upstream.url=https://github.com/MyTeam/product remote.upstream.fetch=+refs/heads/*:refs/remotes/upstream/* remote.pr.url=https://github.com/MyTeam/product remote.pr.fetch=+refs/pull/*:refs/remotes/pr/* ``` ### 開発 1. `git checkout develop` developブランチにうつる(developがない場合は、master等) 2. `git pull upstream develop` 最新のファイルをupstreamのdevelopからpullする 3. `git checkout -b ` 新しいブランチを切る 4. 開発する 5. `git diff --cached` 差分確認してから 6. git commit コミットして 7. `git push origin ` リモートにpush(自分のリモートリポジトリにpushされる) ### Pull Requestを出す 1. https://github.com/MyTeam/product に移動して 2. 自分のoriginのcommitからPull Request 3. Reviewをもらったら(&リポジトリの設定によってはTestをクリアしたら)、Merge 無事にMergeされたら、自分のブランチは削除します(PR画面から削除できる)。 ### ローカルのBranch削除 & update 1. `git branch -d ` でブランチを削除する 2. `git checkout develop` で開発ブランチ(なければmaster)に移動する 2. `git pull upstream develop` で最新状態にする ### Review Pull Requestのレビューを頼まれたら... #### 単発のPRを取得する場合 1. `git fetch upstream pull/1234/head:pr-1234` で取得 2. `git checkout pr-1234` でブランチ移動 #### 全てのPRを同期する 1. `git fetch pr`