GitHub - error: failed to push some refs to '[email protected]:myrepo.git'
GithubGit PushGithub Problem Overview
I am getting the following error. How do I resolve?: git add . git commit -m 't' git push origin development
To [email protected]:myrepo.git
! [rejected] development -> development (non-fast-forward)
error: failed to push some refs to '[email protected]: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.
Github Solutions
Solution 1 - Github
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
Solution 2 - Github
In my case Github was down.
Maybe also check https://www.githubstatus.com/
You can subscribe to notifications per email and text to know when you can push your changes again.
Solution 3 - Github
I have faced the same issue and resolved as follows (if you have a project in local folder then follow the steps):
- create a new repo in guthub
- go to local folder and do "git init"
- git remote add origin (with your repo url) // simply copy from your repo
- git add -A
- git commit -m "your commit"
- git push -u origin master
Solution 4 - Github
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
Solution 5 - Github
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
Solution 6 - Github
you can write in your console:
git pull origin
then press TAB and write your "master" repository
Solution 7 - Github
Try this:
- git push -u origin master
- git push -f origin master
Sometimes #1 works and sometimes #2 for me. I am not sure why it reacts in this way
Solution 8 - Github
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:
Solution 9 - Github
In windows, you need to use double quotes "". So the command would be
git commit -m "t"
Solution 10 - Github
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 simple
That 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
Solution 11 - Github
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
Solution 12 - Github
I have faced below error $ git push origin main error: src refspec main does not match any error: failed to push some refs to 'https://github.com/--------/git-init-sample.git';
Solution : I was not connected to git local repo https://github.com/login/oauth/authorize?response_type=
Once i connected error gone
$ git push origin main Enumerating objects: 3, done. Counting objects: 100% (3/3), done.
Solution 13 - Github
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
Solution 14 - Github
$ git fetch --unshallow origin
$ git push you remote name