Search code examples
gitgithubmergepush

"Git push origin main" does not work for me


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


Solution

  • 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.