Fix error: failed to push some refs to repository in Git

Dung Do Tien Jun 12 2022 597

Hello everyone, I have a project website and use GitHub to help manage source code. Source code still pulls and pushes normally but today after pulling code I had to fix some bugs and push to Git source by using the command:

git push origin main

But I couldn't push all data changed to the origin main branch. I see an issue :  error: failed to push some refs to ''.

$ git push origin main
Username for '': user_test
Password for 'https://[email protected]':
 ![rejected] main -> main (non-fast-forward)
error: failed to push some refs to ''

Not sure about what is happening, I worry will be lost some commit of other people. Please help me, how to fix it?

I'm using git version

Thank you in advance.

Have 4 answer(s) found.
  • E

    Elias Toss Jun 12 2022

    I really got the same problem. I was getting this problem because I had not made any commits, not even an initial commit and still I was trying to push.

    Once I did git commit -m "your comment here", everything worked fine.

  • A

    Anthony Odu Jun 12 2022

    In some cases you need to rename your branch and then push, e.g.:

    git branch -m new_branch_name
    git push -u new_branch_name

    This worked for me.

  • M

    Mohammed Waseem Jun 12 2022

    You can try this solution:

    git reset --mixed origin/main
    git add .
    git commit -m "add comment here"
    git push origin main

    it's worked for me.

  • o

    onwog Jun 12 2022

    I followed the following steps.

    rm -rf .git
     git init
     git add .
     git commit -m "Your comment here"
     git remote add origin ""
     git push -u origin main

    This way worked for me.

Leave An Answer
* NOTE: You need Login before leave an answer

* Type maximum 2000 characters.

* All comments have to wait approved before display.

* Please polite comment and respect questions and answers of others.

Popular Tips

X Close