GitHub - error: failed to push some refs to 'git@github.com:myrepo.git'

I ran these commands below:

git add .
git commit -m 't'

Then, when running the command below:

git push origin development

I got the error below:

To :myrepo.git ! [rejected] development -> development (non-fast-forward)
error: failed to push some refs to ':myrepo.git'
To prevent you from losing history, non-fast-forward updates were rejected
Merge the remote changes (e.g. 'git pull') before pushing again. See the
'Note about fast-forwards' section of 'git push --help' for details.

Are there any ways to solve the error above?

15 Answers

Your origin repository is ahead of your local repository. You'll need to pull down changes from the origin repository as follows before you can push. This can be executed between your commit and push.

git pull origin development

development refers to the branch you want to pull from. If you want to pull from master branch then type this one.

git pull origin master
1

In my case Github was down.

Maybe also check

You can subscribe to notifications per email and text to know when you can push your changes again.

I have faced the same issue and resolved as follows (if you have a project in local folder then follow the steps):

  1. create a new repo in guthub
  2. go to local folder and do "git init"
  3. git remote add origin (with your repo url) // simply copy from your repo
  4. git add -A
  5. git commit -m "your commit"
  6. git push -u origin master

I used this command and it worked fine with me:

>git push -f origin master

But notice, that may delete some files you already have on the remote repo. That came in handy with me as the scenario was different; I was pushing my local project to the remote repo which was empty but the READ.ME

In my case. I had the error because I forgot to make a commit after create a repository on github into an existing project. So I solved:

git add .
git commit -m"commentary"

Then I was able to type:

git push -u origin master

you can write in your console:

git pull origin

then press TAB and write your "master" repository

Try this:

  1. git push -u origin master
  2. git push -f origin master

Sometimes #1 works and sometimes #2 for me. I am not sure why it reacts in this way

1

I also got the error ! [remote rejected] main -> main (failure) error: failed to push some refs to '<repository>'.

Came to find out this is the reason:

enter image description here

In windows, you need to use double quotes "". So the command would be

git commit -m "t"

In my case git push was trying to push more that just the current branch, therefore, I got this error since the other branches were not in sync.

To fix that you could use: git config --global push.default simpleThat will make git to only push the current branch.

This will only work on more recent versions of git. i.e.: won't work on 1.7.9.5

This command worked for me:

git push --set-upstream origin master

And if it doesn't work, please make sure that you are pushing on the current branch that you are on it.

App University>git branch
* master test

And after that, you must push your code on the master branch

 App University>git push origin master

I have faced below error $ git push origin main error: src refspec main does not match any error: failed to push some refs to '

Solution : I was not connected to git local repo

Once i connected error gone

$ git push origin main Enumerating objects: 3, done. Counting objects: 100% (3/3), done.

1

This same error but with a different details can be related to changes to privacy settings in the repository. The details are very clear actually.

In example: I changed my profile settings to hide my email address and that has an effect in all my repositories. However you can keep that setting checked and uncheck "Block command line pushes that expose my email" option in the Email Setting section

I could push with "--force":

git push origin --force
$ git fetch --unshallow origin
$ git push you remote name

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like