HolyMoly
HolyMoly

Reputation: 2080

Can't push to Heroku after a `git filter-branch`: Updates were rejected because the tip of your current branch is behind

I cleaned up my commit history yesterday because there was some private information that had accidentally been pushed. After cleaning my commits, I force pushed to my master branch. Everything is the same both on my computer and in my repo. However, when I try to push to Heroku I get this error:

Updates were rejected because the tip of your current branch is behind its remote counterpart. Integrate the remote changes (e.g.'git pull ...') before pushing again.

So I have been looking through similar threads and have tried:

$ git pull origin master and git pull --rebase origin master

which returns:

 * branch            master     -> FETCH_HEAD
Already up-to-date.

I have also tried git fetch which returns the same response. It says everything is up to date, so why can't I push to heroku? Does this have to do with the git filter-branch I ran yesterday, and how do I fix it?

Upvotes: 2

Views: 1154

Answers (3)

Hidehiro NAGAOKA
Hidehiro NAGAOKA

Reputation: 427

For this works.

heroku plugins:install heroku-repo
heroku repo:reset -a <yourappname>
git push heroku master

Upvotes: 0

S&#233;bastien Dawans
S&#233;bastien Dawans

Reputation: 4626

Git is designed in such a way that it will prevent you from overwriting any branches that have already been pushed to a remote. Your git filter-branch is one of many ways of rewriting a branch's history (you got that part straight in your question).

The --force option on git push lets you update a remote branch regardless of any divergences in history.

Note that technically your private information is not guaranteed to be completely deleted.

  1. It's still in your local repository, in what we call dangling commits
  2. It's still on the objects on the remote, but not necessarily referenced by any branch. If that's the case, it's safe to assume no future clones or fetches will retrieve those objects. If you have command-line access to the git server you might still want to run git gc over there.
  3. It's on anyone else's repository if they have already pulled your branch. There's nothing you can do about this, so you should by default consider your data to be compromised.

Upvotes: 7

HolyMoly
HolyMoly

Reputation: 2080

Well I haven't seen this before, but I figured I would give it a go:

git push --force heroku master

and what do ya know? It worked :)

Upvotes: 2

Related Questions