I was working on my dev branch, then made some commits (A, B, C). I switched to the main branch for some reason at this point, did edits on different parts of the same files I worked on before (the reason why I didn’t notice that I’m on a different branch), then commited D…
* (4th) D (HEAD -> main)
|
| * (3rd) C (dev)
| * (2nd) B
| * (1st) A
| /
|/
* x
* y
* z
What is the most straightforward way to have A, B, C, and D on one branch (doesn’t matter if it’s main or ‘dev`) in the same order they have been created?
>Solution :
From main you can just run git rebase dev. That will replay everything you have in main which isn’t also in dev (just D according to your diagram) onto the tip of dev.
Your main branch will then be in the state you want and your dev branch will be unchanged.