Moving commit diverges branches

I have a repo with a master branch of 4 commits:

1-2-3-4 (HEAD → master)

Then I created a new branch (b2) and made the fifth commit, I merged b2 to master. $ git merge b2 and I got this log :

1-2-3-4-5(HEAD → master, b2)

Now I wanna change the order of commit 2 so I made $ git rebase -i HEAD~5, and I got this log :

1-3-4-2-5 (HEAD → master)

2-3-4-5 (b2)

Two diverge branches.

And the result I want is :

1-3-4-2-5 (HEAD → master, b2)

There are various ways to achieve this:

  • git push origin master:b2 --force-with-lease
  • git checkout b2; git reset --hard master; git push origin b2 --force-with-lease
1 Like

Thank you, this worked.