LoginSignup
7
6

More than 5 years have passed since last update.

branchをとりあえずmasterに追いつかせるための応急措置

Last updated at Posted at 2016-10-18

0. 自分のローカルブランチを切って作業している間にmasterが更新されてしまった場合

[~]git branch
master
* your_branch
[~]git pull origin master
....
CONFLICT (content): Merge conflict in xxxxxxxxxxx  # <= conflictを起こしたファイルがここに表示される
Automatic merge failed; fix conflicts and then commit the result.
  • コンフリクトを起こしている当該ファイルをviなどで開くとコンフリクトを起こしている箇所がマーキングされている。
  • その箇所を消す。またはそれが必要な変更であれば残し、マーキングの行を消す
  • その後以下のようなお決まりの操作をする
[~]git add --all
[~]git commit -m "resolve conflict"
[~]git push origin your_branch

1. masterが更新されてしまったあとに、リモートにあるブランチをmasterに追いつかせたいとき

[~]git branch -r
  origin/HEAD -> origin/master
  origin/xxxx
  origin/hoge
  origin/your_branch  # <= 当該ブランチ
[~]git checkout -b your_branch origin/your_branch
  • ローカルに、リモートにあるブランチと同じ名前のブランチyour_branchを無理やり作成し、そのローカルブランチへリモートにあるブランチorigin/your_branchの内容を反映させる。
  • その後、コンフリクトを解消するなど先ほどと同じ操作をするとmasterの更新内容をbranchに取り込むことが出来る。

ルールがちゃんと決まっている現場ならばそれに従うべきですが、小規模もしくは個人で作業している場合は以上のような応急措置で十分対応可能だと思います。

7
6
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
7
6