Skip to content

Instantly share code, notes, and snippets.

@esperancaJS
Last active March 10, 2023 18:22
Show Gist options
  • Save esperancaJS/e09260d73dfe242859dc to your computer and use it in GitHub Desktop.
Save esperancaJS/e09260d73dfe242859dc to your computer and use it in GitHub Desktop.
git merge –strategy=theirs (closest we can get)

##git merge –strategy=theirs (closest we can get)

get a temp copy of the branch you want to 'clone' into another

git checkout -b tmp <branch to copy from>

merge our version of the branch into the upstream with ours strategy

git merge --strategy=ours <branch to paste into>

checkout our version of the branch

git checkout <branch to paste into>

merge temp (which will be a fast forward)

git merge tmp

get rid of the temp branch

git branch -D temp
@marco-brandizi
Copy link

You don't need the intermediate branch, you can reset --hard the destination (current) branch taking the incoming (theirs) branch as the reset target. Then you can do a merge with the upstream branch with -s ours. I've learned this here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment