つい、先ほどgithubを使い共同開発していたのですが、使い方が分からず困ったのでまとめておきます。
##前提
基本的にメインプログラマーさんのgithubのレポジトリhttps://github.com/mainprogramer/test.git
に、僕がプルリクエストを送る形で開発をします。
##1.Fork
メインプログラマーさんのgithubレポジトリにブラウザでアクセスし、forkボタンを押します。
すると自分のgithubページ上に対象のレポジトリがforkされます。
##2.Clone
自分のPC(ローカル)で編集するために、forkしたレポジトリをcloneします。
$ git clone https://github.com/naogify/test.git
##3.ローカルリポジトリで新規ブランチを作成
修正する前にbranchを作成します。
$ git checkout -b [your_branch_name] Switched to a new branch '[your_branch_name]'
##4.修正を加える(コミット)
修正します。
修正が終わったら'git add'して'git commit'します。
#txtファイルを作成。
$ touch test.txt
#ステージに追加
$ git add test.txt
#コミット
$ git commit -m "add test.txt"
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 test.txt
4を繰り返します。
##5. upstream(Fork元リポジトリ)の設定
Forkした自分のリポジトリ (https://github.com/naogify/test.git) は、Fork元のリポジトリ (https://github.com/mainprogramer/test.git) の変更内容を自動更新しないです。なので、Fork元のリポジトリの最新情報を自分のリポジトリに反映させる必要があります。
ここで、Forkした自分のリポジトリには、大抵デフォルト名としてoriginという名前がついています。新しくFork元のリポジトリにupstreamという名前をつけて追加します。
$ git remote add upstream https://github.com/mainprogramer/test.git
##6.Fork元リポジトリの最新バージョンを取得しlocalのmasterを更新
# branchをmasterに変更
$ git checkout master
# upstreamからfetch & mergeして最新を取得
$ git fetch upstream
$ git merge upstream/master(upstreamとローカルのmasterをマージ)
# localのmasterをoriginにpush(オプション)
$ git push origin master
##8.最新版にしたlocalのmasterとブランチとmerge。
# branchを修正したbranchに変更
$ $ git merge [your_branch_name]
※mergeの時点で、conflictが起こるようであれば、
解決し、もう一度git add
、git commit
してから、git merge
する。
##9.作成したブランチをpush
$ git checkout [your_branch_name]
$ git push origin [your_branch_name]
##10.pullrequestを送る。
github上で相手にpullrequestを送る。
参考:
下の3つのリンクを特に参考にさせて頂きました。
ありがとうございます。
Pull Requestの仕方/Commander-Aipa様
Github Fork Pull Request/Keiko Oda様
GitHubでFork/cloneしたリポジトリを本家リポジトリに追従する/xtetsuji様