Skip to content

Instantly share code, notes, and snippets.

@deepaknverma
Created June 6, 2018 00:45
Show Gist options
  • Save deepaknverma/05dc2a6eaafa535a0d37f47ce87d7a43 to your computer and use it in GitHub Desktop.
Save deepaknverma/05dc2a6eaafa535a0d37f47ce87d7a43 to your computer and use it in GitHub Desktop.
git command

Starting with git version 1.7.3 it became possible to pass a strategy option to git rebase command.

The use of -Xtheirs and -Xours appear to be somewhat counterintuitive, so think of it as telling git which branch code to favor when resolving rebase conflicts. For example, when doing

# see current branch
$ git branch
---
* branch-a
...
# rebase preferring current branch changes merge during conflicts
$ git rebase -Xtheirs branch-b

-Xtheirs will favor your current branch-a code when overwriting merge conflicts, and vice versa -Xours will overwrite merge conflicts with with the code in branch-b.

Similar options exist in git merge command as well, but the meaning of -Xtheirs and -Xours is reversed due to the differences on how git rebase and git merge operate and what they consider ours vs. theirs:

# assuming branch-a is our current version
$ git rebase -Xtheirs branch-b # <- ours: branch-b, theirs: branch-a
$ git merge -Xtheirs branch-b  # <- ours: branch-a, theirs: branch-b

If you are merging changes from origin/master and would like git to favor your current branch code during merge conflicts, you’d need to do this:

$ git merge -Xours origin/master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment