| 0 | kirasiris | Website Tags: , , ,

Heroku GitHub

Deploying your project to GitHub can be tedious and time consuming. Especially when you face the same problem as me. This is the scenario:

Pushing to git@github.com:USERNAME/YOUR_PROJECT.git
To github.com:USERNAME/YOUR_PROJECT
! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'github.com:USERNAME/YOUR_PROJECT'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Merge the remote changes (e.g. 'git pull')
hint: before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

We’re going to try two things, one its trying to fix it by ourselves and/or we will clone it from our last push to Heroku if the first did not work. Let’s start.

The first step it is not necessary but it is something that makes sure not to face problems when installing node_modules again.

  • Go to C:\Users\PCNAME\AppData\Roaming and delete both the npm and npm-cache. If for some reason you can not see the AppData folder, then go to the view tab and check the hidden files.
  • Go into your project, delete and install the node_modules folder again by typing the following
    rm node_modules
    npm install

Now this should fix your problems in most cases. Remember it will still throw some errors but will probably be about missing dependencies; install them one by one or all at once:

npm install dependency dependency

Is it working now?; no?; let’s try something else. We’re going to verify if you don’t have any uncommited changes and if you do, you will need to save them by either commit(git commit) them, stash(git stash save 'I want to keep them safe') them or getting rid off (git reset --hard @{u}) them.

git status

Did you see something similar to this?. If you did not, you’re safe to skip this step:

On branch master
Your branch is up to date with 'heroku/master'.

Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)

modified: client/package-lock.json
modified: client/package.json
modified: package-lock.json
modified: package.json

no changes added to commit (use "git add" and/or "git commit -a")

That means you have uncommited changes, commit/stash them or get rid of them as shown in one of the previous paragraphs. We’re going to do the following:

git reset head

Resetting the head will remove the last commit you made; no useful if you stash them or comitted them. Now I would like to say to uninstall and install the node_modules folder again but that’s just incoherent and unnecessary.

The last trick is what I call the route of last resource and you will have to download the project from Heroku and upload it again to GitHub but this time without errors as everything has been reset to default.

Now it might give you the same error about dependencies again; make sure to fix those first by installing the ones its tells you to. Last but not least important step is to upload it to GitHub.

$ git init
$ git add .
$ git commit -m 'My first commit'
$ git remote add origin <REMOTE_GITHUB_REPOSITORY>
$ git remote -v
$ git push origin master

Everything should be working by now, your app running with not problem at all and uploading it to GitHub should not have given you any errors either.

Please share this post if you found it useful.

Back to Top