Conflicts occur when two branches change the same lines and git cannot automatically merge them. Git marks the conflicting sections with <<<<<<<, =======, and >>>>>>> markers, showing both versions. You must manually choose which changes to keep, then stage and commit the resolved file.
When you encounter a conflict during a merge or rebase, git pauses and waits for you to fix it. Edit the file, remove the conflict markers, keep the version (or combination) you want, and then run git add to mark it resolved. After all conflicts are fixed, run git commit (or git rebase --continue if rebasing) to finish.
$ git merge <branch> # start a merge; stop if conflicts occur $ git status # see which files have conflicts $ git diff # view conflicts with context $ git add <file> # mark a file as resolved $ git commit # complete the merge after resolving $ git merge --abort # cancel a merge and return to the original state
Conflicts are not errors—they are git's way of asking you to make a decision about which changes matter. Take your time to understand both sides of the conflict, test your resolution, and only commit when you are sure. A common strategy is to communicate with your teammate: if their change is important, keep it; if yours is, keep yours; if both matter, combine them.