LoginSignup
0
0

More than 1 year has passed since last update.

後々、mainブランチにマージする時に楽になる方法 => rebaseを使う

Last updated at Posted at 2021-06-03

想定シーン

mainブランチから派生させて作業ブランチでいくつかコミットしている間に、
リモートリポのmainブランチのコミットが進んでいる場合、
作業ブランチをpushする前にmainブランチにpullする際や、作業ブランチをpushしてgithub上でmainブランチにマージする場合、マージコミットが作られてしまうし、マージする際にファイルの変更分をチェックする作業が面倒

=> rebaseを使うとこの面倒な作業を省略できる

シナリオ① rebaseなし

=>マージコミットが作られるし、面倒

シナリオ再現手順

git pull origin main
git checkout -b no_rebase_no_conflict
local.txtを作成
git add local_no_rebase_no_conflict.txt
git commit -m "no conflict no rebase on local"
github上でmainブランチでremote_no_rebase_no_conflict.txt作成
github上でmainブランチでcommit
git checkout no_rebase_no_conflict
git pull origin main(ここで上記で述べた面倒な作業をしなくていはいけないし、マージコミットが発生)
git log --oneline -all --graph(このコマンドでコミット履歴が分岐して把握しにくくなることが確認できる)
git push origin no_rebase_no_conflict

シナリオ② rebaseあり

=>マージコミットが作られないし、楽

シナリオ再現手順

git checkout main
git pull origin main
git checkout -b no_conflict_yes_rebase
local.txtを作成
git add local_no_conflict_yes_rebase.txt
git commit -m "no conflict yes rebase on local"
github上でmainブランチでremote_no_conflict_yes_rebase.txt作成
github上でmainブランチでcommit
git checkout no_conflict_yes_rebase
git pull --rebase origin main
git log --oneline --all --graph(このコマンドでコミット履歴が綺麗で把握しやすいことが確認できる)
git push origin no_conflict_yes_rebase

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