How to fix the Heroku failed to push some refs error? - node.js

I keep getting the failed to push error when trying to push my project to heroku. I followed a couple other answered questions saying to create a new file and push it before connecting to the master, but it still doesn't work for me.
What else can I do to fix this?
image of the error following me creating a text file

The problem here is that you're trying to push the branch master, but that branch doesn't exist. The branch you're on is masterbranch, as seen by the output of your root commit.
If you want to push this branch to the remote, you can use git push origin masterbranch. If you want to push it to the remote master branch, then you can use git remote push masterbranch:master. If you want to rename it, you can use git branch -m master and then push it.

If you pushed your project source code into GitHub, after you deployed to Heroku, branch will be changed from master to main, so to fix it, type following commands:
git add .
git commit -am "changes made"
git push heroku main
Instead of git push heroku master, if branch was changed from master to main.

Related

remote: Pushed to branch other than [main, master], skipping build [duplicate]

I have a project hosted on Heroku and it's gotten to the point where I want to make an alternate test server (so I can test Heroku workers without messing up production).
I have already set up my main Heroku remote running my trunk and a Heroku-dev remote on which I wish to run an alternate branch.
My problem is that since my alternate branch isn't master, Heroku won't build it.
$ git push heroku-dev test
counting objects ...
...
Pushed to non-master branch, skipping build.
To git#heroku.com:example-dev.git
* [new branch] test -> test
Switching this build to master is not an option at the moment. Obviously one option is to create a whole new git repo that's a clone of my test branch, but that doesn't sound very ideal.
You can push an alternative branch to Heroku using Git.
git push heroku-dev test:master
This pushes your local test branch to the remote's master branch (on Heroku).
Comment from #Brian Armstrong:
Worth noting also, when you're ready to go back to master you need to do
git push -f heroku master:master
In my case, the default or base branch was develop, so i used:
git push heroku develop:master
In case git push heroku-dev test:master doesn't work for you, try git push heroku test:master.
Remember the "test" in "test:master" is the name of the new branch you are on.
You will need to pull the remote branch first before you can push the non master branch.
Run following command in you local repository
git pull https://heroku:YOUR_HEROKU_API_KEY#git.heroku.com/YOUR_APP_NAME.git

git#gitlab.com: Permission denied (publickey,keyboard-interactive)

I have a Gitlab repository that contain a number of projects on all of which I can pull and push documents to with Git Bash. I want to set up new project. On the Gitlab website I have created the new project and am following the usual instructions in Git Bash:
cd existing_folder
git init
git remote add origin git#gitlab.com:new_project_name.git
git add .
git commit -m "Initial commit"
git push -u origin master
However when I try push (the last line of the above I get the error:
$ git push -u origin master
error: src refspec master does not match any
error: failed to push some refs to 'git#gitlab.com:new_project_name.git'
(NB: the project name has been replace in this post by new_project_name)
There is a readme file that is ready to be committed.
I know I've missed something or done something incorrectly but I don't know what. I don't understand why I can push to other projects (the pull/ push is working fine) but not this one. What do I need to do in order to git push to the repo?

Error in Github when I do "git push origin master" (error: src refspec master does not match any)

My branch in the Github repository is "master". In the terminal I did:
git branch
and the output is:
* main
my-temporary-work
I wanted to push a file to Github and I used:
git add exploratory_analysis.ipynb
git commit -m "New version"
git push origin master
The "git add" and "git commit" commands work. However, the last command (i.e., "git push origin master") does not work, and I get this error:
error: src refspec master does not match any
error: failed to push some refs to 'git#github.com:NAME-OF-USER/REPOSITORY-NAME.git'
That is, it looks like I cannot push any code from my laptop to Github. How can I fix it?
I faced the same issue some days ago.
If you created a new repository nowadays(2020) then the default branch in main on GitHub.
you can check on GitHub now in your repository branches.
so that's why you need to run
git push origin main
instead of
git push origin master
Goodluck with more details you can watch video
Why are you pushing to master if the branch commands outputs main? Try 'git push origin main'
Also found this explanation for the change:
https://stackoverflow.com/a/65008828/1959534

Push gitlab repository code to Google source repository

I followed below article to push gitlab repository code to Google cloud source repository but I'm getting an error on this command
git push -f google master
error: src refspec master does not match any.
error: failed to push some refs to 'https://source.developers.google.com/p/project/r/test/'
Article followed:
https://medium.com/#bamnet/cloud-source-repositories-gitlab-2fdcf1a8e50c
Is there anything , I'm doing wrong 😜? Any thoughts as to how I can avoid this error message?
src refspec master does not match any
The issue is the date of the article you are following: Aug. 2018.
GitLab Runner has changed since then, more precisely in May 2019.
The problem is described in this thread from May 2019:
Since we are using refspec to clone/fetch the repository, we checkout a specific commit and not checking out a specific branch.
When the script does git push master, the branch is nowhere to be found so git doesn’t know what to push.
That was because of, on GitLab side, MR 1203:
Basically, GitLab CE/EE sends refspecs parameter to GitLab Runner gitlab-org/gitlab-foss app/presenters/ci/build_runner_presenter.rb: this parameter is to used in GitLab Runners for fetching branch/tag refs from remote repository.
This change was introduced because we wanted GitLab Rails side to leverage respecs in order for issue 7380 "Combined ref pipelines (source+target branch)" though, there should not be a big difference between git clone $URL or mkdir $REPO_DIR && git remote add origin $URL && git fetch +refs/heads/branch_name:refs/remotes/origin/branch_name.
In fact, the new behavior has already run on our development project
https://gitlab.com/gitlab-org/gitlab-ce/pipelines and has no issues so far.
Issue 4097 was opened at the time
Workaround
Use HEAD when you want to push this to another remote.
deploy:
stage: deploy
script:
- git remote add heroku https://heroku:$HEROKU_API_KEY#git.heroku.com/<project>.git
- git push -f heroku HEAD:master
So don't push master. Push HEAD.
The OP Adam uses another workaround and add:
before_script:
- git checkout master

can't push to gitlab, failed and rejected

has been pulled, the result is still an error ! [rejected] dev->dev(non-fast-forward)
D:\PPI_Roketin\Project\astrowatch (dev)
λ git add resources/views/reals/_form.blade.php
D:\PPI_Roketin\Project\astrowatch (dev)
λ git commit -m "resources/views/reals/_form.blade.php"
[dev db5ac99] resources/views/reals/_form.blade.php
1 file changed, 2 insertions(+), 2 deletions(-)
D:\PPI_Roketin\Project\astrowatch (dev)
λ git push origin dev
To gitlab.com:roketin-stellar/astrowatch.git
! [rejected] dev -> dev (non-fast-forward)
error: failed to push some refs to 'git#gitlab.com:roketin- stellar/astrowatch.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
error like this, why?
have done git checkout, and repeated the command, it's still an error like above
This is a classic git error. The problem is described in the error message: Updates were rejected because the tip of your current branch is behind, which means that there have been changes to the remote branch that you do not have locally. There are quite a few ways to fix this, one of which is also described in the git message: Integrate the remote changes (e.g. hint: 'git pull ...') before pushing again.
If you do git pull origin dev this will merge whatever changes are made in the remote to your local branch. Once you fix the merge conflicts, you can then push the branch.
Another option would be to run a rebase by performing git pull --rebase origin dev, which will bring in the remote changes and rebase your commits on top of the remote commits. This will result in a cleaner git history.
The easiest for now would probably just doing a git pull, then once it's merged correctly, pushing to your remote.
I definitely recommend researching the git commands and learning how to find the resources correctly in the docs. There is a lot available online.
you can try git reset --hard HEAD
please remind that:
HEAD points to your current branch (or current commit), so all that git reset --hard HEAD will do is to throw away any uncommitted changes you have.
It's quite self explanatory, you need to keep yourself upto date with remote branch if you want to commit and it looks like git pull will overwrite files you've made changes to. You should commit your changes first.

Resources