I am still a beginner at git, warning. This is real code that worked, but it is no guarantee that it will work the same for other things. I hope it still helps someone.
I had the same conflict, and here is what I did in the shell (command: history). It pops up when you have different work done in parallel and you have a merge conflict that must be solved before it pops up.
Being in MY_BRANCH, I ran:
2004 git stash
2005 git checkout master
2006 git fetch
2007 git pull
2018 git checkout MY_BRANCH
2019 git log
# You may also use `git reflog` instead of `git log` to see the
# numbers of the references.
2024 git branch
2026 git status
2027 git rebase -i 633e0424523c4933ba6ab...
2029 git rebase -i HEAD~
2030 git log
2031 git stash apply
2032 git status
2033 git add .
2034 git rebase --continue
2035 git log
2036 git push -f
2037 git branch
2038 git status
2039 git diff master
Main steps:
git stash (in MY_BRANCH)
git pull your master
- rebase to the commit after which different work has been done in parallel
- then
apply your stash to the rebased commit (see all stashes with git stash list
add . your changes to the stage
rebase --continue to take over the work back to MY_BRANCH
push -f the updated work to your branch
- check
diff, the error of "Both Modified" should be gone (in my case at least).
UPDATE:
Even after these changes, I got the same thing again: "Both modified". I am not sure how this came up again since a lot of changes have been made since the answer above. Yet, with some bad luck, the above code does not fully show the way out.
What I had to do when "Both modified" popped up again:
1998 git status
gives:
On branch MY_BRANCH Your branch and 'origin/MY_BRANCH' have diverged,
and have 4 and 1 different commits each, respectively. (use "git
pull" to merge the remote branch into yours)
1999 git reset --hard origin/MY_BRANCH
2000 git pull
2001 git status
2002 git add .
2003 git commit --amend
2004 git push -f
UPDATE2:
I had the issue again, it showed up during rebase since my main and the origin/main were not the same: Your branch is ahead of 'origin/main' by 1 commit.
Two steps:
git checkout main
git reset HEAD^ --soft
were all that was needed. I used the --soft parameter to save it in case of problems. After the reset, the main and the 'origin/main' were the same again and the error that had popped up before during rebase was gone.