[Git] Solving code conflict

고승우·2023년 9월 25일
0

Situation

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.

git merge

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.

git stash

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.

git rebase

I found some good ways to merge code step by step.

  1. Fetch the Latest Changes:
    • git fetch origin
  2. Switch to my Branch:
    • git checkout my-branch
  3. Rebase my Branch:
    • git rebase origin/main
  4. Resolve Conflicts until the end of the commit
    • git add.
    • git rebase --continue
  5. 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.
profile
٩( ᐛ )و 

0개의 댓글