Git Rebase: How to overwrite conflicts automatically

shape
shape
shape
shape
shape
shape
shape
shape

There are certain occasions when Git Rebase will generate dozens or hundreds of conflicts with the Upstream branch, making it very difficult to manage each of these conflicts manually. If you know in advance that your local branch contains more up-to-date code than the remote branch, you can automatically override all these conflicts by keeping the current branch’s code as preferable in the event of a conflict. The opposite is also possible if you wish to use the Upstream Branch code as always preferable in the event of a conflict. This article aims to teach you how to overwrite all these conflicts automatically.

Examples of Git Rebase -Xtheirs and Git Rebase -Xours

In our example, let’s assume we’re using the “feature-A” branch and we want to rebase it with the “feature-B” branch.

When you prefer to always keep the changes of the current branch against the Upstream Branch in case of conflict, you will use Git Rebase with the -Xtheirs parameter:

git rebase -Xtheirs feature-B

# O comando acima irá preferir as alterações da "feature-A" durante qualquer conflito com "feature-B".

The reverse is also possible. When you want to give preference to Upstream Branch changes over the local Branch in case of conflict, use:

git rebase -Xours feature-B

# O comando acima irá preferir as alterações da "feature-B" durante qualquer conflito com "feature-A".

Leave a Reply

Your email address will not be published. Required fields are marked *

Latest news

Latest news directly from our blog.