How to git resolve conflicts quickly from two commands lines.

darker - Aug 20 '22 - - Dev Community

When rebasing/merging, you may face sometimes conflicts, and if you're like me... "LAZY", you just want to get all new changes from the main branch or keep all your current changes as fast as possible depending on the file !

Example

So, for conflicts on some file, you may need to get incoming changes or keep your current changes ! I made two alias for that, git add-their and git add-our !

Under the hood, what it's done is quite simple, in your ~/.gitconfig section, you just have to add those lines :

[alias]
      add-their = !git checkout --ours $@ && git add $@
      add-our = !git checkout --theirs $@ && git add $@
Enter fullscreen mode Exit fullscreen mode

So, how this work, it's mostly two main commands, a checkout command and an add command, let's focus on keywords (theirs and ours) and how they are reverted !

In a context of rebasing, if you're willing to set current changes with these aliases, you should do git add-our and git add-their for incoming ones, that logic is inverted when you're dealing with merge conflicts. this is a good article that go deeply on explanations !

IMPORTANT NOTE : these aliases are only for the one knowing what they are doing, cuz on a complicated conflicts, there is some stuff you will want to keep on both side !

. . . . . . . . . . . .