-1

Whenever I use git push origin main I get an error saying

error: failed to push some refs to "repo link"

to avoid this I have to use master instead of main to create a different branch altogether but when I visit github it already has main and master and if i rename master as main it again doesn't work.

enter image description here

12
  • 2
    What else does the error message tell you? non-fast-forward? There's hundreds of questions plus answers for that Commented Oct 5, 2022 at 19:14
  • 5
    I guess what I'm saying is: please include the full error message (as text, NOT as image) Commented Oct 5, 2022 at 19:21
  • i have, "error: failed to push some refs to main" is the error message i get. I have given it as text. Commented Oct 6, 2022 at 20:08
  • No, that cannot be the full error message. I'm 99% certain that the error message has multiple lines. Commented Oct 7, 2022 at 8:03
  • it is my problem, in my system and I am telling you that it is one error message "error: failed to push some refs to main". Commented Oct 10, 2022 at 16:20

2 Answers 2

1

This is an error I got when I started to learn git, the cause of this error is when you add a remote origin to a git repository, git on the system puts it on master branch but github has moved from master to main (here)

To solve this issue:

  1. Use git checkout -b main to switch to main branch
  2. Use git pull origin main to pull the main branch, add proper flags if you want to merge or rebase the branches
  3. Now you can use git push origin main to push your work to the main branch.
Sign up to request clarification or add additional context in comments.

Comments

0

when I visit github it already has main and master

If you want you local main branch to completely replace the remote GitHub one (and remove master), you would need:

git push --force origin main git push --delete origin master 

2 Comments

I really don't remember how the issue got resolved. Tho this wasn't what I was looking for, thanks.
@VaibhavSinghChandel No problem. Let use know if you get the same error again.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.