ローカルリポジトリを最新版にして、プッシュするまでの流れ

まずはmasterブランチを最新の状態にする

masterに移動

git checkout master


upstream(fork元)から最新のものを取ってくる

git fetch upstream


fetchしたものをローカルのmasterに反映させる(ローカルのmasterを最新にする)

git rebase upstream/master


最新にしたmasterをプッシュしておく

git push origin master



作業ブランチのコミットを1つにまとめてから最新にする

作業ブランチへ移動

git checkout 作業してるブランチ名


作業中のものを避ける

git stash


masterと差分のコミットを一つにまとめる

git rebase -i master


すると、こんな感じのが出てくる

pick ai9j38h 新機能追加
pick onw832h 修正
pick ji8h84h エラー修正

# Rebase bdd3996..bd66e17 onto bdd3996
#
# Commands:
#  p, pick = use commit
#  r, reword = use commit, but edit the commit message
#  e, edit = use commit, but stop for amending
#  s, squash = use commit, but meld into previous commit
#  f, fixup = like "squash", but discard this commit's log message
#  x, exec = run command (the rest of the line) using shell
#
# If you remove a line here THAT COMMIT WILL BE LOST.
# However, if you remove everything, the rebase will be aborted.
#


iを押してINSERTモードにして二つ目以降のコミットのpicksquashへ変更する

pick ai9j38h 新機能追加
squash onw832h 修正
squash ji8h84h エラー修正

# Rebase bdd3996..bd66e17 onto bdd3996
#
# Commands:
#  p, pick = use commit
#  r, reword = use commit, but edit the commit message
#  e, edit = use commit, but stop for amending
#  s, squash = use commit, but meld into previous commit
#  f, fixup = like "squash", but discard this commit's log message
#  x, exec = run command (the rest of the line) using shell
#
# If you remove a line here THAT COMMIT WILL BE LOST.
# However, if you remove everything, the rebase will be aborted.
#

escを押して、:wqで保存する


作業してるブランチを最新にする

git rebase master 作業してるブランチ名


コンフリクトしたら、奴らと戦う


最新にした作業ブランチをプッシュ

git push origin 作業してるブランチ名




参考:GitHubへpull requestする際のベストプラクティス - hnwの日記