I have a local repo with some commits. As I want to make it publicly available to others, I need to push it to a newly created remote repo at Github. The newly created remote repo is initialized with a license file (because the local repo has no license file).
Pushing with git push -u origin main
(my local branch also uses main
instead of master
as the primary branch) produces an error because of the license
file added in the remote repo.
C:\test>git push -u origin main
To https://github.com/pstricks-fans/test.git
! [rejected] main -> main (fetch first)
error: failed to push some refs to 'https://github.com/pstricks-fans/test.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
And I follow the hint by pulling as follows.
C:\test>git pull origin main
From https://github.com/pstricks-fans/test
* branch main -> FETCH_HEAD
fatal: refusing to merge unrelated histories
Merging is not possible.
Someone told me I have to rebase with the following.
C:\test>git pull origin main --rebase
From https://github.com/pstricks-fans/test
* branch main -> FETCH_HEAD
Successfully rebased and updated refs/heads/main.
Question
Is there any other solution without rebasing (for learning purposes)? Rebasing is not recommended for public repo (as the git documentation says).
git pull origin main --allow-unrelated-histories
to merge, if that's what you really want. See stackoverflow.com/a/38680153/182705 for example.