I was working on two branches, and I opened two separate pull requests, one for each branch. After the main branch's code merged, I attempted to merge the code from my branch before the conflict became too significant. I did every dumb things.
I tried to merge with
git merge origin main, I encountered two problems.
1. Auto merge failed so I have to manually merge the code.
2. After merging my code, another code was also merged with the main branch. WhenI tried to merge my code by executing
git merge origin main once again, I I received a message "Already updated".
Maybe I've done something wrong. But let's focus on how I treated this problem.
I thought then let's git stash the main branch's code and take it to my branches. Yeah I overlooked something.
In Git, each branch maintains its own stash!. It failed.
I found some good ways to merge code step by step.
- Fetch the Latest Changes:
git fetch origin
- Switch to my Branch:
git checkout my-branch
- Rebase my Branch:
git rebase origin/main
- Resolve Conflicts until the end of the commit
git rebase --continue
- Push Updated Branch
git push origin my-branch
Despite I spent so many time in solving conflicts, I think this experience to ve valuable. This issue has reinforced studying git is very important. Perhaps there are easier way to solve these conflicts. If I discover any, I'll write down it.