Git Your branch and 'origin/dev' have diverged

the following error occurred while executing git push :
Your branch and "origin/dev" have diverged,and have 1 and 2 different commits each, respectively.

I work on two computers. After both computers An and B started as up-to-date, I first commit and push in An a few times, and then I now write from the initial state on computer B, and then try to push, after commit (using the same local and cloud branch).

now I want to merge the two, show the difference, and then re-commit and push

Git
Mar.30,2021

suppose that the commit on the remote is A-> B
after you commit and push on computer A, the remote becomes A-> B-> C-> D
now, on computer B, it is still A-> B . Then you commit, so on computer B is A-> B-> E .

so, what you need is to change the history line on computer B into A-> B-> C-> D-> E
at this point, you need to be on computer B:

git pull --rebase origin dev

this command is equivalent to:

git fetch origin
git rebase origin/dev
After

execution, the history line on computer B becomes A-> B-> C-> D-> E , and then you can push

. < hr > By the way, the above "error" is displayed because A-> B-> C-> D and A-> B-> E have a common ancestor B , you have a local commit E , and two more commits C and D remotely. At this point, if you want to push on the branch of A-> B-> E , git can't guess whether you want to keep C and D , or just E , or both, the above prompt will appear.

Menu