Dealing with messy merge conflicts can be a bit like navigating heavy traffic. With a bit of patience, forward-thinking, and sometimes a pal, you can resolve any conflict you're faced with. Take a deep breath and follow the steps below to get those resolutions in place!
Pull down all the latest code from the main branch of your remote repo.
Merge all that fresh new code into your feature branch locally.
git rebase origin/main
[Optional] Run this to get a high-level look at which files have conflicts.
Fix all the merge conflicts in your project.
- Go to those files in your editor. You will see that it shows you the code that lives on the HEAD and your branch's code.
- Keep the good code that you need when it asks you to choose and delete the code you don't want. This can be the most challenging part because you might be seeing code from your team that you don't recognize -- pair with your pals to decide what code goes and what code stays if necessary.
- When you see that the files that previously had conflicts are squared away, save them!
Stage all the files that you fixed.
git add .
Continue the rebase to see what's next.
git rebase --continue
You may still have more conflicts to work through because the rebase is going to compare every commit that came down from the main branch to your feature branch. Keep the following steps 3-6 until you're taken back to your feature branch.
Push your updated code up to your remote repository.
git push --force-with-lease
--force-with-lease is a safer option than
force because it will not overwrite any work on the remote branch if more commits were added to the remote branch. Read more here.