I have two branches that diverge more than they should.
Since this has been marked as duplicate, let me clarify my question.
I already know that I can just do git push -f
to force the merge. That's what I've done already several times. My question is more about the inner workings of git. If I add a new file to my branch B, I can commit it and push it without any problem. But if I git checkout branch-A somefile.txt
and then git add
and git push
, I get the error below. Why does this kind of commit seem to always result in that error when pushing?
End edit.
To reconcile them to a common ancestor, I have to copy some files from one branch to the other. These are files that should actually have been there but got lost somehow in the process. Every time I do that using git checkout branch-A somefile.txt
, commit, and push, the origin gives me this error:
"Updates were rejected because the tip of your current branch is behind its remote counterpart. Integrate the remote branches before pushing again."
Why is that?
More detail, if needed: The two branches diverged before we started using git. Now I'm trying to sew them together. I am making sure both branches are correct and all files are identical that should be, so that I can then create a merge point that actually makes sense. They are each a branch of the same repo. In finding their common point of ancestry, I've noticed some files that should have been on both branches are missing from one or the other ( probably the result of some mistake I made when putting them under git). To fix that, I simply git checkout branch-A missingfile.txt
into branch B, git add
, git commit
, and git push
. But for some reason every time I push, I get the "out of date" error and have to do a force push. Which is fine if I know I only changed one file, but if I've changed/copied a bunch, then I always have to double check to make sure there isn't some error.