How do I force a subtree push to overwrite remote changes?

The trick was to chain the subtree split into a forced push:

git push origin `git subtree split --prefix dist master`:production --force

I got this from the Addendum of http://clontz.org/blog/2014/05/08/git-subtree-push-for-deployment/, who actually references this answer on Stack Overflow. I had skimmed this one earlier but Steve Clontz's post made it click for me.


I've just enhanced the answer of ele adding generic expressions <> to make it more clear:

git push <remote> `git subtree split --prefix <local-folder> <local-branch>`:<remote-branch> --force

Example values

<remote>

origin
other-origin-name
https://github.com/full-url/of-repo

<local-folder>

Local folder path relative to repo root e.g.: /dist (you need to execute this command in root btw)

<remote-branch>

master
any-other-branchname