How do I solve “pushed branch tip is behind” on subtree when deploying to Heroku with Git?

Viewed 477

I'm trying to push my build folder, dist-new, with this command:

git subtree push --prefix dist-new heroku master

Unfortunately, I get this error:

error: failed to push some refs to 'https://git.heroku.com/it
ribe-frontend.git'
hint: Updates were rejected because a pushed branch tip is be
hind its remote
hint: counterpart. Check out this branch and integrate the re
mote changes
hint: (e.g. 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help'

I can't force the deployment, because git subtree does not have a force option.

Googling around, I've seen a recommendation to do this:

git push heroku git subtree split --prefix dist master:master --force

But that throws this error:

error: unknown option `prefix'

Does anyone have any ideas?

2 Answers

Problem

You likely aren’t using an up to date version of git

Solution

The prefix option is still available in the latest version of git (see here: https://github.com/git/git/blob/master/contrib/subtree/git-subtree.sh)

git subtree split -- prefix

Also you need to execute the command as a sub shell you can’t just do:

git push heroku git subtree split --prefix dist master:master --force

You must do:

git push heroku $(git subtree split --prefix dist master:master) --force

References

Git Subtree source code: https://github.com/git/git/blob/master/contrib/subtree/git-subtree.sh

Related