I have created a Repository as the default main branch.
Step I tried to add to the repository:
Now I have stuck to push to the origin
I have tried git push -u origin main
but it gave me an error as:
! [rejected] main -> main (fetch first) error: failed to push some refs to 'my git url'
How to push the code from my local machine to GitHub in the main branch?
Any help and pointing to the documentation will be appreciated.
I tried to pull first and there is also an error on doing that:
$ git pull origin main
From
my git url
* branch
main -> FETCH_HEAD fatal: refusing to merge unrelated histories
That only happens because your remote repository was initialized not empty, but with some files (README.md
for instance)
That is why force pushing is a good option (in that case)
git push -f -u origin main
If you had created the repository empty, a regular push would have been enough.