When someone tries to make changes (edit or delete) some lines in the same file where you are making changes.
git fetch remote
will fetch the changes to the current branch.
But when we try to rebase with the fetched changes git rebase remote/branch_name
, error something like this can come.
First, rewinding head to replay your work on top of it...
Applying: some_commit_name
Using index info to reconstruct a base tree...
A file_path/file_name.cc
Falling back to patching base and 3-way merge...
Auto-merging some_other_file_path/some_other_file_name.cc
CONFLICT (content): Merge conflict in some_other_file_path/some_other_file_name.cc
error: Failed to merge in the changes.
Patch failed at 0001 some_commit_name
The copy of the patch that failed is found in: .git/rebase-apply/patch
When you have resolved this problem, run "git rebase --continue".
If you prefer to skip this patch, run "git rebase --skip" instead.
To check out the original branch and stop rebasing, run "git rebase --abort".
Go to the file where merge conflict has happened. In the file some_other_file_name.cc
, there will be some conflict markers like this:
<<<<<<<
: Following this, chages are from based branch or the HEAD
=======
: Following this, chages are yours which you are trying to update and is conflicting with a newly pushed code(before you get the chance to push).
>>>>>>>
: This is the end marker for the merger conflict.
In the some_other_file_name.cc
, make changes (either incorporate or remove) and delete the conflict markers.
After this, git rebase --continue
If more conflict comes, then fix those files and keep on continuing.
At the end, messege like this will appear:
some_other_file_path/some_other_file_name.cc: needs merge
You must edit all merge conflicts and then
mark them as resolved using git add
Once all the conficts are resolved locally, do a final git rebase --continue
Follwing message will appear:
Applying: some_commit
Following this, push the changes on your branch for review.
git push my_remote_upstream branch_name
In case of any error, or problem which is not understood in a straight forward way, restore the initial state by:
git rebase --abort