-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

  • 2
    What else does the error message tell you? non-fast-forward? There's hundreds of questions plus answers for that – knittl Oct 05 '22 at 19:14
  • 5
    I guess what I'm saying is: please include the _full_ error message (as text, NOT as image) – knittl Oct 05 '22 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. – Vaibhav Singh Chandel Oct 06 '22 at 20:08
  • No, that cannot be the full error message. I'm 99% certain that the error message has multiple lines. – knittl Oct 07 '22 at 08: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". – Vaibhav Singh Chandel Oct 10 '22 at 16:20
  • @knittl Where do you see an image in this question? I really dont see how you were 99% sure. Ig it would have been better had I given a picture so you'd know that it actually was the message that I received. – Vaibhav Singh Chandel Aug 06 '23 at 19:50
  • I don't see an image, and neither do I see the _full_ error message. I asked to include the _full_ error message as text (and not as image). – knittl Aug 06 '23 at 19:53
  • You would not see an image because i never put one there, also this was the full error message I am sure of that because I have seen it. – Vaibhav Singh Chandel Aug 06 '23 at 19:54
  • No, this is definitely not the full error message and it is incomplete. It is not even a full sentence and the error message of Git that starts with this phrase is several lines long: it includes the remote repository address (or alias) and the refs that failed to push. (I never claimed there was an image in the question, I only pointed out that the full error message shoudl be added as text) – knittl Aug 06 '23 at 19:58
  • @knittl Hey, just to prove my point I replicated the whole process and I guess I did omit some part of the full error message, sorry for that. I have now also added that as a picture, so you can see the whole error. I also gave an answer to solve it below. – Vaibhav Singh Chandel Aug 10 '23 at 04:30
  • Remember when I asked you to post the full error message as text and _not as picture_ (several times even)? Yet, you upload a picture? Did you read hint lines that Git provided, informing you about your local branch name? Additionally, every prompt line clearly shows `master` as the current branch name – knittl Aug 10 '23 at 06:20
  • well read the question i have provided both text and image, and actually the solution too. – Vaibhav Singh Chandel Aug 10 '23 at 06:25

2 Answers2

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.
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 
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250