git error: failed to push some refs to remote
For some reason, I can't push now, whereas I could do it yesterday. Maybe I messed up with configs or something.
This is what happens:
When I use the git push origin master
What my working directory and remote repository looks like:
If the GitHub repo has seen new commits pushed to it, while you were working locally, I would advise using:
git pull --rebase git push
The full syntax is:
git pull --rebase origin master git push origin master
With Git 2.6+ (Sept. 2015), after having done (once)
git config --global pull.rebase true git config --global rebase.autoStash true
git pull would be enough.
(Note: with Git 2.27 Q2 2020, a
merge.autostash is also available for your regular pull, without rebase)
That way, you would replay (the
--rebase part) your local commits on top of the newly updated
git pull origin yourBranch).
I would recommend a:
# add and commit first git push -u origin master
That would establish a tracking relationship between your local master branch and its upstream branch.
After that, any future push for that branch can be done with a simple:
Since the OP already reset and redone its commit on top of
git reset --mixed origin/master git add . git commit -m "This is a new commit for what I originally planned to be amended" git push origin master
There is no need to
git reset --mixed origin/master can also be written
git reset origin/master, since the
--mixed option is the default one when using
Read more… Read less…
Did anyone try:
git push -f origin master
That should solve the problem.
EDIT: Based on @Mehdi ‘s comment below I need to clarify something about
—force pushing. The git command above works safely only for the first commit. If there were already commits, pull requests or branches in previous, this resets all of it and set it from zero. If so, please refer @VonC ‘s detailed answer for better solution.
If you just used
git init and have added your files with
git add . or something similar and have added your remote branch it might be that you just haven't committed (
git commit -m 'commit message') anything locally to push to the remote... I just had this error and that was my issue.
I had same problem. I was getting this problem because i had not made any commit not even initial commit and still i was trying to push.
Once i did
git commit -m "your msg" and then everything worked fine.
Rename your branch and then push, e.g.:
git branch -m new-name git push -u new-name
This worked for me.
I find the solution to this problem in github help.
You can see it from:Dealing with non-fast-forward errors
You can fix this by fetching and merging the changes made on the remote branch with the changes that you have made locally:
$ git fetch origin # Fetches updates made to an online repository $ git merge origin branch # Merges updates made online with your local work
Or, you can simply use git pull to perform both commands at once:
$ git pull origin branch # Grabs online updates and merges them with your local work