What it means
Git won't merge two histories with no shared ancestor by default, because it's usually a mistake: the wrong remote, or a remote initialised separately with a README or licence.
Causes and fixes
Most likely first. Run the check, and if it matches, apply the fix.
1. The remote was created with its own first commit and you have your own
Check:
git log --oneline origin/main | tail -1; git log --oneline main | tail -1
Fix: If it's really the same project, git pull origin main --allow-unrelated-histories once, then resolve conflicts.
2. The remote URL points at the wrong repository
Check:
git remote -v
Fix: git remote set-url origin <right-url>.
Fix it yourself
A live machine in your browser with this problem already on it. The grader checks the result.
Open the labNo account needed for your first tries.
Related errors
- error: failed to push some refs to ... (fetch first / non-fast-forward)
The remote branch has commits you don't have, so pushing would throw them away.