For full guide, please refer on :
Credit on original author
In this repo there is three branch
master
branch_a
(fork from master)branch_b
(fork from master)
# Clone this repo
git clone https://github.com/todiadiyatmo/resolve_conflict/
# checkout branch_a
git checkout -b local origin/branch_a
# to merge branch_b
git merge origin/branch_b
When you merge branch a and b there will be conflict.
Now examine the home.html
, which is in conflict
Line 7 (<<<<<<<
) is a special code from git to mark the begining of the conflict
Line 9 (=======
) is the separator between the code from local and remote branch
Line 11 (>>>>>>
) ending of merge conflict
The code from branch_a
is between line 7 and 9. Code from branch_b
is between line 9 and 11.
You can resolve the conflict without tool, just pick the line you want to keep. and delete the :
<<<<<<< HEAD
and
=======
and
>>>>>>> branch_b
For example if we want to use code from branch_b
instead of branch_a
:
Remove line 7,8,9 + line 11.
To finish the merging process, issue a merge command
git add .
git commit -m "fixed merge conflict,using branch_b"
To easily merge a conflict you will need a good merge tool. Some options in ubuntu/linux is :
- meld
- kdiff3
No make your prefered merge tool as the default merge tool using this command
git config --global merge.tool kdiff3
You can run merge tool by using this command :
git mergetool -t kdiff3
OR
# Assuming you already set the mergetool using global config
git mergetool
This message will appear if you are running git mergetool
command :
KDiff 3 is my preference mergetool because it has 4 pane
- Base -> Before Conflict
- Local -> Your Current Branch
- Remote -> Remote Branch that you want to merge
- Combined File
To merge using kdiff3
After you satistfied with your merged file, don't forget issue a save command on the kdiff3
Finnaly, issue a commit command
git add .
git commit -m "fixed merge conflict,using"