3

I had a situation, where I git pushed, then, I changed the commit message causing a new checksum on that commit. Then when I tried to push next time the remote had changes which were not stored in my local repository, so i did a git pull and all good.

To my error message:

I tried to do a git push heroku and it said that the heroku repository did not exist. I could not think of a reason why this was possibly other than I have everything on a external harddrive and I did some work on my laptop but did not push to heroku or anything and besides everything is in my .git folder and I didnt change anything.

I did a I believe

git remote -a heroku git@heroku.com:myapp.git
git remote
heroku
origin

Now it says this is set. But I try do a git push heroku and I get the error;

To https://git.heroku.com/myapp.git
 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'https://git.heroku.com/myapp.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

I never looked into git to much other than doing the normal git commands and pushing to origin and to heroku. What is this error message telling me?

I looked into my .git folder under refs/remotes and there is only origin folder, no heroku. I cannot understand what has happened here.

P.S I realise I should never have had to of made another heroku remote locally but my .git folder was hidden on windows and I could not inspect it to see if my refs/remotes/heroku was there (as it shoud be) and posted a question about this.

Thanks.

EDITTTTTTTTTTTT: The answer here may be something quite strange. I copied my myapp folder to a external drive but the .git folder must have went with it but like the error shows, there doesn't seem to be any heroku remote so I still cant understand why its like heroku remote has vanished. Either way, the last push to heroku was when my app folder was not on the external drive. It seems something has happened...

Lee Eather
  • 345
  • 3
  • 16
  • 1
    Did you try to do a `git pull heroku`? The error that you see means that the remote repository has commits which you do not have locally, so before pushing you need to pull these commits. Depending on what you did locally in the meanwhile, you'll have to merge your local work with these remote changes or rebase your local commits onto the latest remote commits. – Sky Feb 13 '20 at 07:55
  • Haha. Yes I was just coming to this conclusion. See my edit either way I believe that is the right step you mentioned. – Lee Eather Feb 13 '20 at 07:58
  • Can you please clarify that by locally you mean in `refs/remotes/heroku`? IE this is what the error message is saying or it means locally as in my local repository, which I believe is in `refs/heads`. So the `git pull heroku` will update `refs/remotes/heroku`? – Lee Eather Feb 13 '20 at 08:20
  • I believe anyway that the pull merges to the local anyway... – Lee Eather Feb 13 '20 at 11:06
  • You should not need to do anything inside the `.git` folder - that's git internal stuff and not meant to be touched. The `refs` folder just contains references to specific commits, e.g., `.git/refs/heads/master` is a reference to the current master branch commit. To check which remotes are there, type `git remote -v`. I'm not sure what you wanted to do with your external drive, but yes, if you copy everything including the `.git` folder, then you have a complete copy of your repository, which should work. Did you try to push changes from both your local disk and external drive? – Sky Feb 13 '20 at 12:19
  • I believe that git would update it if the heroku remote wasn't in there but I copied the one from my old project folder I copied and it all went fine. Couldn't tell anyone why the heroku remote dissapeared. Yeah like what your saying, after I copied the remote into the external folder and tried to push without pulling first the error message was different, but still saying there were changes on the remote so I did what you said and then everything seemed to be up to date. I new the new changes would not have been anything crazy so thats what I did. You can answer it if you like the question.. – Lee Eather Feb 14 '20 at 03:06
  • "Either way, the last push to heroku was when my app folder was not on the external drive"—so you need to get that commit onto your hard drive copy. Git is distributed: pull from wherever your original copy is, where the new commit exists, to your hard drive copy. Or go through GitHub / GitLab / Bitbucket / whatever you want. – ChrisGPT was on strike Feb 14 '20 at 21:35
  • ([_Don't_ use Heroku for this](https://devcenter.heroku.com/articles/git-clone-heroku-app): "A Heroku app’s Git repository is intended for deployment purposes only. Cloning from this repository is not officially supported as a feature and should be attempted only as a last resort. **Do not** use this repository as your app’s canonical “origin” repository. Instead, use your own Git server or a version control service such as GitHub.") – ChrisGPT was on strike Feb 14 '20 at 21:35
  • Yah, but I guess we gotta pull if its telling us that. I would have done a bunch of commits mucking around trying to get something working on heroku and likely did what I did on the origin copy and edited a commit message after pushing, then pushed to origin – Lee Eather Feb 15 '20 at 08:53

0 Answers0