git "You have divergent branches" when I havent made any changes or commits

1.6k Views Asked by At

I cloned a repo, then later I want to pull the latest version. I have made no modifications or commits locally.

However, git pull says this:

fatal: Need to specify how to reconcile divergent branches.

git status says this:

Your branch and 'origin/main' have diverged,
and have 2 and 1 different commits each, respectively.

I have not made a commit. Only the author has.

If I do git log, I can see all commits are by the original author, not me.

How can I find out why git thinks I have made a commit?

2

There are 2 best solutions below

0
UpAndAdam On BEST ANSWER

(Similar to @Jay but a little bit simpler with a command I use quite often. That said, I think his answer is awesome. If you upvote mine, I strongly encourage you to upvote his)

It seems somebody has force-pushed to the remote main branch, effectively deleting the last two commits known to your local branch and replacing them with a new commit.

You can adjust your local branch to point to the same commit as the remote branch using:
git reset --hard origin/main

6
Jay On

It seems somebody has force-pushed to the remote main branch,
effectively deleting the last two commits known to your local branch and replacing them with a new commit.

If you don't have uncommitted changes, you can adjust your local branch to point to the same commit as the remote branch using

git reset --hard HEAD@{upstream}

Short version:

git reset --hard @{u}