Skip to main content

Section C.7 Merge Conflicts

Hopefully you never have to deal with these. Sometimes, they are pretty simple to fix. Other times, it can cause some headaches. To avoid merge conflicts, pull from upstream often (Warning 5.4.3.1 and Warning 6.4.2.1). Merge conflicts are caused when more than one person edits the same line of a file. It is possible for two people to edit the same file, but on different lines, and not cause a conflict.
I have never caused or had to deal with a serious merge conflict. The GitHub documentation 69  has a good post on how to resolve conflicts on GitHub. GitHub will even show you the two (or more) versions and let you choose how to resolve them. You can also resolve merge conflicts on the command line 70  or in your text editor.
I have accidentally caused a merge conflict with myself and with working on the same repository from two different computers and two different accounts. Oops! This is an easy fix because I made the conflict with myself so I know which version is the correct one. If this happens to you, Git might send you to an unfamiliar screen when you try to push or pull. You’ll know you have this case if your terminal asks you to type in a reason why the merge must happen or how the conflict is resolved. This typically happens when you try to merge from an upstream main into a local main that has active changes (so create branches!).
If you start to get stuck, do a quick Google search. There are many guides and resources out there to help with merge conflicts. Jennifer Bryan 71  has a good guide on merge conflict basics (and some other potential Git issues!) so start there and explore more as needed.
This is for when you are sent into a command line editing tool or a default text editor asking you to provide a reason why the merge is necessary. This may not solve your problem but sometimes all a merge conflict needs is to bypass this screen.

(a)

Type i

(b)

Type a merge message. This can be something as simple as “I have to merge to move on” or “I know what I want, let me do it” (yes, I have actually put that as a message…is this good? Who knows?).

(c)

Press esc.

(d)

Type :wq (this stands for write and quit)

(e)

Press Enter and you may be ok to move forward with the pushing, pulling, and creating of pull requests.