LoginSignup
12
14

More than 5 years have passed since last update.

GitHub Flow でのリポジトリ運用手順 (Shared repository model)

Last updated at Posted at 2015-07-14

チーム内の Git リポジトリを GitHub Flow で運用することになったので説明用に手順を書き出してみました。
Fork & pull でない運用モデル (Shared repository model) の想定です。

1. git clone <repository>

まず、リポジトリをリモートからローカルにクローンします。

$ git clone hoge

2. git checkout -b <topic-branch> master

次に、作業を行うためトピックブランチを作成しチェックアウトします。
ブランチ名は説明的な名前にします。

$ git checkout -b new-feature master

-b はブランチの作成を同時に行うためのオプションで、以下のコマンドと同じ挙動になります。

$ git branch new-feature  # ブランチの作成
$ git checkout new-feature  # ブランチのチェックアウト

3. Edit files

ファイルの修正を行います。

4. git add

修正したファイルをステージングエリアに追加します。

$ git add -A

-A で追加、修正、削除したすべてのファイルがステージングされます。

5. git commit -m <msg>

コミットします。

$ git commit -m 'Add a new feature'

6. git checkout master

トピックブランチでの作業が終わったので master をチェックアウトします。

$ git checkout master

7. git pull origin master

pull して master を最新化します。

$ git pull origin master

8. git checkout <topic-branch>

再度トピックブランチをチェックアウト。

$ git checkout new-feature

9. git rebase master

master でリベースします。

$ git rebase master

自動マージできた場合は以下のようなメッセージが出力されます。次のステップに進みましょう。

First, rewinding head to replay your work on top of it...
Applying: Add a new feature

自動マージに失敗した場合はコンフリクトした旨が表示されます。

First, rewinding head to replay your work on top of it...
Applying: Change a message
Using index info to reconstruct a base tree...
M       main.go
Falling back to patching base and 3-way merge...
Auto-merging main.go
CONFLICT (content): Merge conflict in main.go
Failed to merge in the changes.
Patch failed at 0001 Change a message
The copy of the patch that failed is found in:
   /hoge/.git/rebase-apply/patch

When you have resolved this problem, run "git rebase --continue".
If you prefer to skip this patch, run "git rebase --skip" instead.
To check out the original branch and stop rebasing, run "git rebase --abort".

main.go でコンフリクトが起きているようです。

CONFLICT (content): Merge conflict in main.go

ファイルを修正したら git add して git rebase --continue でリベースを完了します。

10. git push origin <topic-branch>

リベースし終わったトピックブランチをリモートにプッシュします。

$ git push origin new-feature

11. Create pull request on GitHub

プッシュしたことで GitHub のリポジトリに Your recently pushed branches としてトピックブランチが表示されているはずです。

1_mini.jpg

Compare & pull request を選択します。

2_mini.jpg

プルリクエストの作成画面に遷移するので、必要であればコメントや Asignee (レビュアーのアサイン) を入力して Create pull request を選択。

3_mini.jpg

プルリクエストが作成されました。レビュアーからのアクション (マージかリジェクト) されるのを待ちます。

12
14
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
12
14